Files
omnivore/packages/api/test/gql/sanitize-directive.test.ts
Hongbo Wu 7569e988bf upgrade typeorm to 3.0 (#359)
* upgrade typeorm to 3.0

* use new datasource object in typeorm 3

* fix tests

* fix tests

* migrate before creating connection

* fail the test if migration failed
2022-04-06 10:32:41 +08:00

59 lines
1.4 KiB
TypeScript

import { createTestUser, deleteTestUser } from '../db'
import { graphqlRequest, request } from '../util'
import { User } from '../../src/entity/user'
import { hashPassword } from '../../src/utils/auth'
import 'mocha'
describe('Sanitize Directive', () => {
const username = 'fake_user'
const correctPassword = 'fakePassword'
let authToken: string
let user: User
before(async () => {
const hashedPassword = hashPassword(correctPassword)
user = await createTestUser(username, '', hashedPassword)
const res = await request
.post('/local/debug/fake-user-login')
.send({ fakeEmail: user.email })
authToken = res.body.authToken
})
after(async () => {
await deleteTestUser(username)
})
describe('Update user with a bio that is too long', () => {
let bio = ''.padStart(500, '*')
let query: string
beforeEach(() => {
query = `
mutation {
updateUser(
input: {
name: "fakeUser"
bio: "${bio}"
}
) {
... on UpdateUserSuccess {
user {
id
}
}
... on UpdateUserError {
errorCodes
}
}
}
`
})
it('responds status code 500 when invalid input', async () => {
return graphqlRequest(query, authToken).expect(400)
})
})
})