flamingo.me/flamingo-commerce/v3@v3.11.0/test/integrationtest/projecttest/modules/customer/fake_service.go (about) 1 package customer 2 3 import ( 4 "context" 5 "errors" 6 "time" 7 8 "flamingo.me/flamingo-commerce/v3/customer/domain" 9 "flamingo.me/flamingo/v3/core/auth" 10 ) 11 12 type ( 13 // FakeService returns the hard configured customer with ID from given auth or identity 14 FakeService struct{} 15 16 customer struct { 17 id string 18 personalData domain.PersonData 19 addresses []domain.Address 20 defaultShippingAddress *domain.Address 21 defaultBillingAddress *domain.Address 22 } 23 ) 24 25 var ( 26 _ domain.CustomerIdentityService = new(FakeService) 27 _ domain.Customer = new(customer) 28 ) 29 30 // GetByIdentity retrieves the authenticated customer by Identity 31 func (f FakeService) GetByIdentity(_ context.Context, identity auth.Identity) (domain.Customer, error) { 32 if identity != nil { 33 return getCustomer(identity.Subject()), nil 34 } 35 36 return nil, errors.New("not logged in") 37 } 38 39 // GetID of the customer 40 func (c customer) GetID() string { 41 return c.id 42 } 43 44 // GetPersonalData of the customer 45 func (c customer) GetPersonalData() domain.PersonData { 46 return c.personalData 47 } 48 49 // GetAddresses of the customer 50 func (c customer) GetAddresses() []domain.Address { 51 return c.addresses 52 } 53 54 // GetDefaultShippingAddress of the customer 55 func (c customer) GetDefaultShippingAddress() *domain.Address { 56 return c.defaultShippingAddress 57 } 58 59 // GetDefaultBillingAddress of the customer 60 func (c customer) GetDefaultBillingAddress() *domain.Address { 61 return c.defaultBillingAddress 62 } 63 64 func getCustomer(id string) *customer { 65 birthdayOfFlamingoCommerce, _ := time.Parse("2006-01-02", "2019-04-02") 66 return &customer{ 67 id: id, 68 personalData: domain.PersonData{ 69 Gender: domain.GenderMale, 70 FirstName: "Flamingo", 71 LastName: "Commerce", 72 MiddleName: "C.", 73 MainEmail: "flamingo@aoe.com", 74 Prefix: "Mr.", 75 Birthday: birthdayOfFlamingoCommerce, 76 Nationality: "DE", 77 }, 78 addresses: nil, 79 defaultShippingAddress: nil, 80 defaultBillingAddress: nil, 81 } 82 }