@@ -13,6 +13,7 @@ import (
1313 "github.com/tidepool-org/platform/auth/client"
1414 "github.com/tidepool-org/platform/auth/service/service"
1515 "github.com/tidepool-org/platform/auth/store"
16+ storetest "github.com/tidepool-org/platform/auth/store/test"
1617 platformclient "github.com/tidepool-org/platform/client"
1718 "github.com/tidepool-org/platform/devicetokens"
1819 logtest "github.com/tidepool-org/platform/log/test"
@@ -46,14 +47,14 @@ var _ = Describe("Client", func() {
4647 name := "test auth client"
4748 logger := logtest .NewLogger ()
4849 if authStore == nil {
50+ repo := storetest .NewDeviceTokenRepository ()
51+ repo .Tokens = map [string ][]* devicetokens.DeviceToken {
52+ testUserID : {
53+ testDeviceToken1 ,
54+ }}
55+
4956 authStore = & mockAuthStore {
50- DeviceTokenRepository : & mockDeviceTokenRepository {
51- Tokens : map [string ][]* devicetokens.DeviceToken {
52- testUserID : {
53- testDeviceToken1 ,
54- },
55- },
56- },
57+ DeviceTokenRepository : repo ,
5758 }
5859 }
5960 providerFactory := & mockProviderFactory {}
@@ -80,10 +81,10 @@ var _ = Describe("Client", func() {
8081 ctx := context .Background ()
8182 server := NewServer ()
8283 defer server .Close ()
84+ repo := storetest .NewDeviceTokenRepository ()
85+ repo .Error = fmt .Errorf ("test error" )
8386 authStore := & mockAuthStore {
84- DeviceTokenRepository : & mockDeviceTokenRepository {
85- Error : fmt .Errorf ("test error" ),
86- },
87+ DeviceTokenRepository : repo ,
8788 }
8889 serviceClient := newTestServiceClient (server .URL (), authStore )
8990
@@ -115,37 +116,3 @@ type mockProviderFactory struct{}
115116func (f * mockProviderFactory ) Get (typ string , name string ) (provider.Provider , error ) {
116117 return nil , nil
117118}
118-
119- type mockDeviceTokenRepository struct {
120- Error error
121- Tokens map [string ][]* devicetokens.DeviceToken
122- }
123-
124- func (r * mockDeviceTokenRepository ) GetAllByUserID (ctx context.Context , userID string ) ([]* devicetokens.Document , error ) {
125- if r .Error != nil {
126- return nil , r .Error
127- }
128-
129- if tokens , ok := r .Tokens [userID ]; ok {
130- docs := make ([]* devicetokens.Document , 0 , len (tokens ))
131- for _ , token := range tokens {
132- docs = append (docs , & devicetokens.Document {DeviceToken : * token })
133- }
134- return docs , nil
135- }
136- return nil , nil
137- }
138-
139- func (r * mockDeviceTokenRepository ) Upsert (ctx context.Context , doc * devicetokens.Document ) error {
140- if r .Error != nil {
141- return r .Error
142- }
143- return nil
144- }
145-
146- func (r * mockDeviceTokenRepository ) EnsureIndexes () error {
147- if r .Error != nil {
148- return r .Error
149- }
150- return nil
151- }
0 commit comments