@@ -14,6 +14,7 @@ import (
1414 "github.com/tidepool-org/platform/auth/client"
1515 "github.com/tidepool-org/platform/auth/service/service"
1616 "github.com/tidepool-org/platform/auth/store"
17+ storetest "github.com/tidepool-org/platform/auth/store/test"
1718 platformclient "github.com/tidepool-org/platform/client"
1819 "github.com/tidepool-org/platform/devicetokens"
1920 logtest "github.com/tidepool-org/platform/log/test"
@@ -47,14 +48,14 @@ var _ = Describe("Client", func() {
4748 name := "test auth client"
4849 logger := logtest .NewLogger ()
4950 if authStore == nil {
51+ repo := storetest .NewDeviceTokenRepository ()
52+ repo .Tokens = map [string ][]* devicetokens.DeviceToken {
53+ testUserID : {
54+ testDeviceToken1 ,
55+ }}
56+
5057 authStore = & mockAuthStore {
51- DeviceTokenRepository : & mockDeviceTokenRepository {
52- Tokens : map [string ][]* devicetokens.DeviceToken {
53- testUserID : {
54- testDeviceToken1 ,
55- },
56- },
57- },
58+ DeviceTokenRepository : repo ,
5859 }
5960 }
6061 providerFactory := & mockProviderFactory {}
@@ -81,10 +82,10 @@ var _ = Describe("Client", func() {
8182 ctx := context .Background ()
8283 server := NewServer ()
8384 defer server .Close ()
85+ repo := storetest .NewDeviceTokenRepository ()
86+ repo .Error = fmt .Errorf ("test error" )
8487 authStore := & mockAuthStore {
85- DeviceTokenRepository : & mockDeviceTokenRepository {
86- Error : fmt .Errorf ("test error" ),
87- },
88+ DeviceTokenRepository : repo ,
8889 }
8990 serviceClient := newTestServiceClient (server .URL (), authStore )
9091
@@ -120,37 +121,3 @@ type mockProviderFactory struct{}
120121func (f * mockProviderFactory ) Get (typ string , name string ) (provider.Provider , error ) {
121122 return nil , nil
122123}
123-
124- type mockDeviceTokenRepository struct {
125- Error error
126- Tokens map [string ][]* devicetokens.DeviceToken
127- }
128-
129- func (r * mockDeviceTokenRepository ) GetAllByUserID (ctx context.Context , userID string ) ([]* devicetokens.Document , error ) {
130- if r .Error != nil {
131- return nil , r .Error
132- }
133-
134- if tokens , ok := r .Tokens [userID ]; ok {
135- docs := make ([]* devicetokens.Document , 0 , len (tokens ))
136- for _ , token := range tokens {
137- docs = append (docs , & devicetokens.Document {DeviceToken : * token })
138- }
139- return docs , nil
140- }
141- return nil , nil
142- }
143-
144- func (r * mockDeviceTokenRepository ) Upsert (ctx context.Context , doc * devicetokens.Document ) error {
145- if r .Error != nil {
146- return r .Error
147- }
148- return nil
149- }
150-
151- func (r * mockDeviceTokenRepository ) EnsureIndexes () error {
152- if r .Error != nil {
153- return r .Error
154- }
155- return nil
156- }
0 commit comments