@@ -19,19 +19,19 @@ describe('DeleteAccountConfirmRequest', () => {
1919
2020 describe ( 'constructor()' , ( ) => {
2121 it ( 'should initialize a request instance from options' , ( ) => {
22- let res = HttpMocks . createResponse ( )
22+ const res = HttpMocks . createResponse ( )
2323
24- let accountManager = { }
25- let userStore = { }
24+ const accountManager = { }
25+ const userStore = { }
2626
27- let options = {
27+ const options = {
2828 accountManager,
2929 userStore,
3030 response : res ,
3131 token : '12345'
3232 }
3333
34- let request = new DeleteAccountConfirmRequest ( options )
34+ const request = new DeleteAccountConfirmRequest ( options )
3535
3636 expect ( request . response ) . to . equal ( res )
3737 expect ( request . token ) . to . equal ( options . token )
@@ -42,17 +42,17 @@ describe('DeleteAccountConfirmRequest', () => {
4242
4343 describe ( 'fromParams()' , ( ) => {
4444 it ( 'should return a request instance from options' , ( ) => {
45- let token = '12345'
46- let accountManager = { }
47- let userStore = { }
45+ const token = '12345'
46+ const accountManager = { }
47+ const userStore = { }
4848
49- let req = {
49+ const req = {
5050 app : { locals : { accountManager, oidc : { users : userStore } } } ,
5151 query : { token }
5252 }
53- let res = HttpMocks . createResponse ( )
53+ const res = HttpMocks . createResponse ( )
5454
55- let request = DeleteAccountConfirmRequest . fromParams ( req , res )
55+ const request = DeleteAccountConfirmRequest . fromParams ( req , res )
5656
5757 expect ( request . response ) . to . equal ( res )
5858 expect ( request . token ) . to . equal ( token )
@@ -62,16 +62,16 @@ describe('DeleteAccountConfirmRequest', () => {
6262 } )
6363
6464 describe ( 'get()' , ( ) => {
65- let token = '12345'
66- let userStore = { }
67- let res = HttpMocks . createResponse ( )
65+ const token = '12345'
66+ const userStore = { }
67+ const res = HttpMocks . createResponse ( )
6868 sinon . spy ( res , 'render' )
6969
7070 it ( 'should create an instance and render a delete account form' , ( ) => {
71- let accountManager = {
71+ const accountManager = {
7272 validateDeleteToken : sinon . stub ( ) . resolves ( true )
7373 }
74- let req = {
74+ const req = {
7575 app : { locals : { accountManager, oidc : { users : userStore } } } ,
7676 query : { token }
7777 }
@@ -86,10 +86,10 @@ describe('DeleteAccountConfirmRequest', () => {
8686 } )
8787
8888 it ( 'should display an error message on an invalid token' , ( ) => {
89- let accountManager = {
89+ const accountManager = {
9090 validateDeleteToken : sinon . stub ( ) . throws ( )
9191 }
92- let req = {
92+ const req = {
9393 app : { locals : { accountManager, oidc : { users : userStore } } } ,
9494 query : { token }
9595 }
@@ -106,33 +106,26 @@ describe('DeleteAccountConfirmRequest', () => {
106106 it ( 'creates a request instance and invokes handlePost()' , ( ) => {
107107 sinon . spy ( DeleteAccountConfirmRequest , 'handlePost' )
108108
109- let token = '12345'
110- let host = SolidHost . from ( { serverUri : 'https://example.com' } )
111- let alice = {
109+ const token = '12345'
110+ const host = SolidHost . from ( { serverUri : 'https://example.com' } )
111+ const alice = {
112112 webId : 'https://alice.example.com/#me'
113113 }
114- let storedToken = { webId : alice . webId }
115- let store = {
116- findUser : sinon . stub ( ) . resolves ( alice ) ,
117- updatePassword : sinon . stub ( )
118- }
119- let accountManager = {
114+ const storedToken = { webId : alice . webId }
115+ const accountManager = {
120116 host,
121- store,
122117 userAccountFrom : sinon . stub ( ) . resolves ( alice ) ,
123118 validateDeleteToken : sinon . stub ( ) . resolves ( storedToken )
124119 }
125120
126121 accountManager . accountExists = sinon . stub ( ) . resolves ( true )
127122 accountManager . loadAccountRecoveryEmail = sinon . stub ( ) . resolves ( '[email protected] ' ) 128123
129- // TODO: @kjetilk write in your stuff here - probably a stub
130-
131- let req = {
132- app : { locals : { accountManager, oidc : { users : store } } } ,
124+ const req = {
125+ app : { locals : { accountManager, oidc : { users : { } } } } ,
133126 body : { token }
134127 }
135- let res = HttpMocks . createResponse ( )
128+ const res = HttpMocks . createResponse ( )
136129
137130 return DeleteAccountConfirmRequest . post ( req , res )
138131 . then ( ( ) => {
@@ -143,18 +136,18 @@ describe('DeleteAccountConfirmRequest', () => {
143136
144137 describe ( 'handlePost()' , ( ) => {
145138 it ( 'should display error message if validation error encountered' , ( ) => {
146- let token = '12345'
147- let userStore = { }
148- let res = HttpMocks . createResponse ( )
149- let accountManager = {
139+ const token = '12345'
140+ const userStore = { }
141+ const res = HttpMocks . createResponse ( )
142+ const accountManager = {
150143 validateResetToken : sinon . stub ( ) . throws ( )
151144 }
152- let req = {
145+ const req = {
153146 app : { locals : { accountManager, oidc : { users : userStore } } } ,
154147 query : { token }
155148 }
156149
157- let request = DeleteAccountConfirmRequest . fromParams ( req , res )
150+ const request = DeleteAccountConfirmRequest . fromParams ( req , res )
158151
159152 return DeleteAccountConfirmRequest . handlePost ( request )
160153 . then ( ( ) => {
@@ -166,10 +159,10 @@ describe('DeleteAccountConfirmRequest', () => {
166159
167160 describe ( 'validateToken()' , ( ) => {
168161 it ( 'should return false if no token is present' , ( ) => {
169- let accountManager = {
162+ const accountManager = {
170163 validateDeleteToken : sinon . stub ( )
171164 }
172- let request = new DeleteAccountConfirmRequest ( { accountManager, token : null } )
165+ const request = new DeleteAccountConfirmRequest ( { accountManager, token : null } )
173166
174167 return request . validateToken ( )
175168 . then ( result => {
@@ -181,9 +174,9 @@ describe('DeleteAccountConfirmRequest', () => {
181174
182175 describe ( 'error()' , ( ) => {
183176 it ( 'should invoke renderForm() with the error' , ( ) => {
184- let request = new DeleteAccountConfirmRequest ( { } )
177+ const request = new DeleteAccountConfirmRequest ( { } )
185178 request . renderForm = sinon . stub ( )
186- let error = new Error ( 'error message' )
179+ const error = new Error ( 'error message' )
187180
188181 request . error ( error )
189182
@@ -192,20 +185,42 @@ describe('DeleteAccountConfirmRequest', () => {
192185 } )
193186
194187 describe ( 'deleteAccount()' , ( ) => {
195- // TODO: @kjetilk Write test when more is in place
188+ it ( 'should remove user from userStore and remove directories' , ( ) => {
189+ const webId = 'https://alice.example.com/#me'
190+ const user = { webId, id : webId }
191+ const accountManager = {
192+ userAccountFrom : sinon . stub ( ) . returns ( user )
193+ }
194+ const userStore = {
195+ deleteUser : sinon . stub ( ) . resolves ( )
196+ }
197+
198+ const options = {
199+ accountManager, userStore, newPassword : 'swordfish'
200+ }
201+ const request = new DeleteAccountConfirmRequest ( options )
202+ const tokenContents = { webId }
203+
204+ return request . deleteAccount ( tokenContents )
205+ . then ( ( ) => {
206+ expect ( accountManager . userAccountFrom ) . to . have . been . calledWith ( tokenContents )
207+ expect ( userStore . deleteUser ) . to . have . been . calledWith ( user . id )
208+ // TODO: @kjetilk Include the last method for deleting from fs
209+ } )
210+ } )
196211 } )
197212
198213 describe ( 'renderForm()' , ( ) => {
199214 it ( 'should set response status to error status, if error exists' , ( ) => {
200- let token = '12345'
201- let response = HttpMocks . createResponse ( )
215+ const token = '12345'
216+ const response = HttpMocks . createResponse ( )
202217 sinon . spy ( response , 'render' )
203218
204- let options = { token, response }
219+ const options = { token, response }
205220
206- let request = new DeleteAccountConfirmRequest ( options )
221+ const request = new DeleteAccountConfirmRequest ( options )
207222
208- let error = new Error ( 'error message' )
223+ const error = new Error ( 'error message' )
209224
210225 request . renderForm ( error )
211226
0 commit comments