Skip to content

Commit aa7277c

Browse files
authored
Merge pull request #32 from solid/delete-pod
Delete User from store
2 parents ddadd0c + ff806e6 commit aa7277c

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"standard": "standard",
88
"test": "npm run standard && npm run mocha",
9-
"mocha": "nyc mocha --exit --timeout=20000 test/**/*.js",
9+
"mocha": "nyc mocha",
1010
"preversion": "npm test",
1111
"postversion": "git push --follow-tags"
1212
},

src/user-store.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,19 @@ class UserStore {
194194
})
195195
.then(() => this.backend.put('users', userKey, user))
196196
}
197+
/**
198+
* Permanently deletes the files of a user
199+
*
200+
* @param user {UserAccount}
201+
*
202+
* @return {Promise}
203+
*/
204+
205+
deleteUser (user) {
206+
let userKey = UserStore.normalizeIdKey(user.id)
207+
208+
return this.backend.del('users', userKey)
209+
}
197210

198211
/**
199212
* Saves an "alias" user object, used for linking local account IDs to

test/integration/user-store-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,35 @@ describe('UserStore (integration)', () => {
143143
})
144144
})
145145
})
146+
describe('deleteUser()', () => {
147+
it('deletes a previously saved user', () => {
148+
let options = { path: dbPath, saltRounds: 2 }
149+
let store = UserStore.from(options)
150+
store.initCollections()
151+
152+
let user = {
153+
id: 'alice.example.com',
154+
155+
}
156+
let password = '12345'
157+
158+
return store.createUser(user, password)
159+
.then(() => {
160+
return store.findUser(user.id)
161+
})
162+
.then(foundUser => {
163+
expect(foundUser.id).to.equal(user.id)
164+
expect(foundUser.email).to.equal(user.email)
165+
})
166+
.then(() => {
167+
return store.deleteUser(user)
168+
})
169+
.then(() => {
170+
return store.findUser(user.id)
171+
})
172+
.then(foundUser => {
173+
expect(foundUser).to.not.exist()
174+
})
175+
})
176+
})
146177
})

test/mocha.opts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--exit
2+
--recursive
3+
--timeout 20000

test/unit/user-store-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,21 @@ describe('UserStore', () => {
212212
})
213213
})
214214
})
215+
216+
describe('deleteUser', () => {
217+
let store
218+
219+
beforeEach(() => {
220+
store = UserStore.from({ path: './db' })
221+
})
222+
223+
it('should call backend.del with normalized user id', () => {
224+
let userId = 'alice.solidtest.space/profile/card#me'
225+
226+
store.backend.del = sinon.stub()
227+
228+
store.deleteUser({ id: userId })
229+
expect(store.backend.del).to.have.been.calledWith('users', UserStore.normalizeIdKey(userId))
230+
})
231+
})
215232
})

0 commit comments

Comments
 (0)