1
+ import DatabaseManager from '../src' ;
2
+
3
+ export default class Database {
4
+ public name ;
5
+
6
+ constructor ( name ) {
7
+ this . name = name ;
8
+ }
9
+
10
+ public createUser ( ) {
11
+ return this . name ;
12
+ }
13
+
14
+ public findUserById ( ) {
15
+ return this . name ;
16
+ }
17
+
18
+ public findUserByEmail ( ) {
19
+ return this . name ;
20
+ }
21
+
22
+ public findUserByUsername ( ) {
23
+ return this . name ;
24
+ }
25
+
26
+ public findPasswordHash ( ) {
27
+ return this . name ;
28
+ }
29
+
30
+ public findUserByEmailVerificationToken ( ) {
31
+ return this . name ;
32
+ }
33
+
34
+ public findUserByResetPasswordToken ( ) {
35
+ return this . name ;
36
+ }
37
+
38
+ public findUserByServiceId ( ) {
39
+ return this . name ;
40
+ }
41
+
42
+ public addEmail ( ) {
43
+ return this . name ;
44
+ }
45
+
46
+ public removeEmail ( ) {
47
+ return this . name ;
48
+ }
49
+
50
+ public verifyEmail ( ) {
51
+ return this . name ;
52
+ }
53
+
54
+ public setUsername ( ) {
55
+ return this . name ;
56
+ }
57
+
58
+ public setPassword ( ) {
59
+ return this . name ;
60
+ }
61
+
62
+ public setProfile ( ) {
63
+ return this . name ;
64
+ }
65
+
66
+ public setService ( ) {
67
+ return this . name ;
68
+ }
69
+
70
+ public unsetService ( ) {
71
+ return this . name ;
72
+ }
73
+
74
+ public createSession ( ) {
75
+ return this . name ;
76
+ }
77
+
78
+ public updateSession ( ) {
79
+ return this . name ;
80
+ }
81
+
82
+ public invalidateSession ( ) {
83
+ return this . name ;
84
+ }
85
+
86
+ public invalidateAllSessions ( ) {
87
+ return this . name ;
88
+ }
89
+
90
+ public findSessionByToken ( ) {
91
+ return this . name ;
92
+ }
93
+
94
+ public findSessionById ( ) {
95
+ return this . name ;
96
+ }
97
+
98
+ public addEmailVerificationToken ( ) {
99
+ return this . name ;
100
+ }
101
+
102
+ public addResetPasswordToken ( ) {
103
+ return this . name ;
104
+ }
105
+
106
+ public setResetPassword ( ) {
107
+ return this . name ;
108
+ }
109
+ }
110
+
111
+ const databaseManager = new DatabaseManager ( {
112
+ userStorage : new Database ( 'userStorage' ) ,
113
+ sessionStorage : new Database ( 'sessionStorage' ) ,
114
+ } ) ;
115
+
116
+ describe ( 'DatabaseManager configuration' , ( ) => {
117
+
118
+ it ( 'should throw if no configuration object specified' , ( ) => {
119
+ expect ( ( ) => databaseManager . validateConfiguration ( ) ) . toThrow ( ) ;
120
+ } ) ;
121
+
122
+ it ( 'should throw if no userStorage specified' , ( ) => {
123
+ expect ( ( ) => databaseManager . validateConfiguration ( { sessionStorage : true } ) ) . toThrow ( ) ;
124
+ } ) ;
125
+
126
+ it ( 'should throw if no sessionStorage specified' , ( ) => {
127
+ expect ( ( ) => databaseManager . validateConfiguration ( { userStorage : true } ) ) . toThrow ( ) ;
128
+ } ) ;
129
+
130
+ it ( 'should throw if no sessionStorage specified' , ( ) => {
131
+ expect ( ( ) =>
132
+ databaseManager . validateConfiguration ( {
133
+ userStorage : true ,
134
+ sessionStorage : true ,
135
+ } )
136
+ ) . not . toThrow ( ) ;
137
+ } ) ;
138
+
139
+ } ) ;
140
+
141
+
142
+ describe ( 'DatabaseManager' , ( ) => {
143
+
144
+ it ( 'createUser should be called on userStorage' , ( ) => {
145
+ expect ( databaseManager . createUser ( ) ) . toBe ( 'userStorage' ) ;
146
+ } ) ;
147
+
148
+ it ( 'findUserById should be called on userStorage' , ( ) => {
149
+ expect ( databaseManager . findUserById ( ) ) . toBe ( 'userStorage' ) ;
150
+ } ) ;
151
+
152
+ it ( 'findUserByEmail should be called on userStorage' , ( ) => {
153
+ expect ( databaseManager . findUserByEmail ( ) ) . toBe ( 'userStorage' ) ;
154
+ } ) ;
155
+
156
+ it ( 'findUserByUsername should be called on userStorage' , ( ) => {
157
+ expect ( databaseManager . findUserByUsername ( ) ) . toBe ( 'userStorage' ) ;
158
+ } ) ;
159
+
160
+ it ( 'findPasswordHash should be called on userStorage' , ( ) => {
161
+ expect ( databaseManager . findPasswordHash ( ) ) . toBe ( 'userStorage' ) ;
162
+ } ) ;
163
+
164
+ it ( 'findUserByEmailVerificationToken should be called on userStorage' , ( ) => {
165
+ expect ( databaseManager . findUserByEmailVerificationToken ( ) ) . toBe ( 'userStorage' ) ;
166
+ } ) ;
167
+
168
+ it ( 'findUserByResetPasswordToken should be called on userStorage' , ( ) => {
169
+ expect ( databaseManager . findUserByResetPasswordToken ( ) ) . toBe ( 'userStorage' ) ;
170
+ } ) ;
171
+
172
+ it ( 'findUserByServiceId should be called on userStorage' , ( ) => {
173
+ expect ( databaseManager . findUserByServiceId ( ) ) . toBe ( 'userStorage' ) ;
174
+ } ) ;
175
+
176
+ it ( 'addEmail should be called on userStorage' , ( ) => {
177
+ expect ( databaseManager . addEmail ( ) ) . toBe ( 'userStorage' ) ;
178
+ } ) ;
179
+
180
+ it ( 'removeEmail should be called on userStorage' , ( ) => {
181
+ expect ( databaseManager . removeEmail ( ) ) . toBe ( 'userStorage' ) ;
182
+ } ) ;
183
+
184
+ it ( 'verifyEmail should be called on userStorage' , ( ) => {
185
+ expect ( databaseManager . verifyEmail ( ) ) . toBe ( 'userStorage' ) ;
186
+ } ) ;
187
+
188
+ it ( 'setUsername should be called on userStorage' , ( ) => {
189
+ expect ( databaseManager . setUsername ( ) ) . toBe ( 'userStorage' ) ;
190
+ } ) ;
191
+
192
+ it ( 'setPassword should be called on userStorage' , ( ) => {
193
+ expect ( databaseManager . setPassword ( ) ) . toBe ( 'userStorage' ) ;
194
+ } ) ;
195
+
196
+ it ( 'setProfile should be called on userStorage' , ( ) => {
197
+ expect ( databaseManager . setProfile ( ) ) . toBe ( 'userStorage' ) ;
198
+ } ) ;
199
+
200
+ it ( 'setService should be called on userStorage' , ( ) => {
201
+ expect ( databaseManager . setService ( ) ) . toBe ( 'userStorage' ) ;
202
+ } ) ;
203
+
204
+ it ( 'unsetService should be called on userStorage' , ( ) => {
205
+ expect ( databaseManager . unsetService ( ) ) . toBe ( 'userStorage' ) ;
206
+ } ) ;
207
+
208
+ it ( 'createSession should be called on sessionStorage' , ( ) => {
209
+ expect ( databaseManager . createSession ( ) ) . toBe ( 'sessionStorage' ) ;
210
+ } ) ;
211
+
212
+ it ( 'updateSession should be called on sessionStorage' , ( ) => {
213
+ expect ( databaseManager . updateSession ( ) ) . toBe ( 'sessionStorage' ) ;
214
+ } ) ;
215
+
216
+ it ( 'invalidateSession should be called on sessionStorage' , ( ) => {
217
+ expect ( databaseManager . invalidateSession ( ) ) . toBe ( 'sessionStorage' ) ;
218
+ } ) ;
219
+
220
+ it ( 'invalidateAllSessions should be called on sessionStorage' , ( ) => {
221
+ expect ( databaseManager . invalidateAllSessions ( ) ) . toBe ( 'sessionStorage' ) ;
222
+ } ) ;
223
+
224
+ it ( 'findSessionByToken should be called on sessionStorage' , ( ) => {
225
+ expect ( databaseManager . findSessionByToken ( ) ) . toBe ( 'sessionStorage' ) ;
226
+ } ) ;
227
+
228
+ it ( 'findSessionById should be called on sessionStorage' , ( ) => {
229
+ expect ( databaseManager . findSessionById ( ) ) . toBe ( 'sessionStorage' ) ;
230
+ } ) ;
231
+
232
+ it ( 'addEmailVerificationToken should be called on sessionStorage' , ( ) => {
233
+ expect ( databaseManager . addEmailVerificationToken ( ) ) . toBe ( 'userStorage' ) ;
234
+ } ) ;
235
+
236
+ it ( 'addResetPasswordToken should be called on sessionStorage' , ( ) => {
237
+ expect ( databaseManager . addResetPasswordToken ( ) ) . toBe ( 'userStorage' ) ;
238
+ } ) ;
239
+
240
+ it ( 'setResetPassword should be called on sessionStorage' , ( ) => {
241
+ expect ( databaseManager . setResetPassword ( ) ) . toBe ( 'userStorage' ) ;
242
+ } ) ;
243
+
244
+ }
0 commit comments