mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Add tests for User validations
This commit is contained in:
parent
b4ffa13517
commit
4fbabc879f
@ -4,7 +4,7 @@ module.exports = {
|
||||
id: { type: 'string', primary: true, default: uuid }, // TODO: should be type: 'uuid' but simplified for our tests
|
||||
actorId: { type: 'string', allow: [null] },
|
||||
name: { type: 'string', disallow: [null], min: 3 },
|
||||
slug: 'string',
|
||||
slug: { type: 'string', regex: /^[a-z0-9_-]+$/, lowercase: true },
|
||||
encryptedPassword: 'string',
|
||||
avatar: { type: 'string', allow: [null] },
|
||||
coverImg: { type: 'string', allow: [null] },
|
||||
|
||||
@ -18,3 +18,44 @@ describe('role', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('slug', () => {
|
||||
it('normalizes to lowercase letters', async () => {
|
||||
const user = await instance.create('User', { slug: 'Matt' })
|
||||
await expect(user.toJson()).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
slug: 'matt',
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe('characters', () => {
|
||||
const createUser = attrs => {
|
||||
return instance.create('User', attrs).then(user => user.toJson())
|
||||
}
|
||||
|
||||
it('-', async () => {
|
||||
await expect(createUser({ slug: 'matt-rider' })).resolves.toMatchObject({
|
||||
slug: 'matt-rider',
|
||||
})
|
||||
})
|
||||
|
||||
it('_', async () => {
|
||||
await expect(createUser({ slug: 'matt_rider' })).resolves.toMatchObject({
|
||||
slug: 'matt_rider',
|
||||
})
|
||||
})
|
||||
|
||||
it(' ', async () => {
|
||||
await expect(createUser({ slug: 'matt rider' })).rejects.toThrow(
|
||||
/fails to match the required pattern/,
|
||||
)
|
||||
})
|
||||
|
||||
it('ä', async () => {
|
||||
await expect(createUser({ slug: 'mätt' })).rejects.toThrow(
|
||||
/fails to match the required pattern/,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user