mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add api tests for deleting a user
This commit is contained in:
parent
e5d6386b96
commit
5db87db1c6
1 changed files with 69 additions and 0 deletions
69
packages/api/test/resolvers/user_delete_account.test.ts
Normal file
69
packages/api/test/resolvers/user_delete_account.test.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import { createTestUser } from '../db'
|
||||
import { graphqlRequest, request } from '../util'
|
||||
import * as chai from 'chai'
|
||||
import { expect } from 'chai'
|
||||
import 'mocha'
|
||||
import { User } from '../../src/entity/user'
|
||||
import chaiString from 'chai-string'
|
||||
import { DeleteAccountErrorCode } from '../../src/generated/graphql'
|
||||
|
||||
chai.use(chaiString)
|
||||
|
||||
const deleteAccountRequest = async (authToken: string, userId: string) => {
|
||||
const mutation = `
|
||||
mutation {
|
||||
deleteAccount(
|
||||
input: {
|
||||
userId: "${userId}",
|
||||
}
|
||||
) {
|
||||
... on DeleteAccountSuccess {
|
||||
userId
|
||||
}
|
||||
... on DeleteAccountError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
return graphqlRequest(mutation, authToken).expect(200)
|
||||
}
|
||||
|
||||
describe('the deleteAccount API', () => {
|
||||
const username = 'fakeUser'
|
||||
let authToken: string
|
||||
let user: User
|
||||
|
||||
before(async () => {
|
||||
// create test user and login
|
||||
user = await createTestUser(username)
|
||||
const res = await request
|
||||
.post('/local/debug/fake-user-login')
|
||||
.send({ fakeEmail: user.email })
|
||||
|
||||
authToken = res.body.authToken
|
||||
})
|
||||
|
||||
context('deleting a user that exists', () => {
|
||||
it('should return a unauthorized error if authToken is invalid', async () => {
|
||||
const res = await deleteAccountRequest('invalid-auth-token', user.id)
|
||||
expect(res.body.data.deleteAccount.errorCodes).to.contain(
|
||||
DeleteAccountErrorCode.Unauthorized
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the user id after a successful user deletion', async () => {
|
||||
const res = await deleteAccountRequest(authToken, user.id)
|
||||
expect(res.body.data.deleteAccount.userId).to.eql(user.id)
|
||||
})
|
||||
})
|
||||
|
||||
context('deleting a user that does not exist', () => {
|
||||
it('should return a user not found error if user id is invalid', async () => {
|
||||
const res = await deleteAccountRequest(authToken, 'invalid-user-id')
|
||||
expect(res.body.data.deleteAccount.errorCodes).to.contain(
|
||||
DeleteAccountErrorCode.UserNotFound
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
Reference in a new issue