fix tests
This commit is contained in:
@ -55,7 +55,7 @@ export class UserPersonalization {
|
||||
updatedAt!: Date
|
||||
|
||||
@Column('json')
|
||||
fields?: any | null
|
||||
fields?: any
|
||||
|
||||
@Column('jsonb')
|
||||
digestConfig?: any
|
||||
|
||||
@ -2,22 +2,22 @@ import { DeepPartial } from 'typeorm'
|
||||
import { UserPersonalization } from '../entity/user_personalization'
|
||||
import { authTrx } from '../repository'
|
||||
|
||||
export const findUserPersonalization = async (id: string, userId: string) => {
|
||||
export const findUserPersonalization = async (userId: string) => {
|
||||
return authTrx(
|
||||
(t) =>
|
||||
t.getRepository(UserPersonalization).findOneBy({
|
||||
id,
|
||||
user: { id: userId },
|
||||
}),
|
||||
undefined,
|
||||
userId
|
||||
)
|
||||
}
|
||||
|
||||
export const deleteUserPersonalization = async (id: string, userId: string) => {
|
||||
export const deleteUserPersonalization = async (userId: string) => {
|
||||
return authTrx(
|
||||
(t) =>
|
||||
t.getRepository(UserPersonalization).delete({
|
||||
id,
|
||||
user: { id: userId },
|
||||
}),
|
||||
undefined,
|
||||
userId
|
||||
|
||||
@ -22,7 +22,7 @@ describe('User Personalization API', () => {
|
||||
.post('/local/debug/fake-user-login')
|
||||
.send({ fakeEmail: user.email })
|
||||
|
||||
authToken = res.body.authToken
|
||||
authToken = res.body.authToken as string
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
@ -61,25 +61,17 @@ describe('User Personalization API', () => {
|
||||
res.body.data.setUserPersonalization.updatedUserPersonalization.fields
|
||||
).to.eql(fields)
|
||||
|
||||
const userPersonalization = await findUserPersonalization(
|
||||
res.body.data.setUserPersonalization.updatedUserPersonalization.id,
|
||||
user.id
|
||||
)
|
||||
const userPersonalization = await findUserPersonalization(user.id)
|
||||
expect(userPersonalization).to.not.be.null
|
||||
|
||||
// clean up
|
||||
await deleteUserPersonalization(
|
||||
res.body.data.setUserPersonalization.updatedUserPersonalization.id,
|
||||
user.id
|
||||
)
|
||||
await deleteUserPersonalization(user.id)
|
||||
})
|
||||
})
|
||||
|
||||
context('when user personalization exists', () => {
|
||||
let existingUserPersonalization: UserPersonalization
|
||||
|
||||
before(async () => {
|
||||
existingUserPersonalization = await saveUserPersonalization(user.id, {
|
||||
await saveUserPersonalization(user.id, {
|
||||
user: { id: user.id },
|
||||
fields: {
|
||||
testField: 'testValue',
|
||||
@ -89,7 +81,7 @@ describe('User Personalization API', () => {
|
||||
|
||||
after(async () => {
|
||||
// clean up
|
||||
await deleteUserPersonalization(existingUserPersonalization.id, user.id)
|
||||
await deleteUserPersonalization(user.id)
|
||||
})
|
||||
|
||||
it('updates the user personalization', async () => {
|
||||
@ -106,7 +98,6 @@ describe('User Personalization API', () => {
|
||||
).to.eql(newFields)
|
||||
|
||||
const updatedUserPersonalization = await findUserPersonalization(
|
||||
existingUserPersonalization.id,
|
||||
user.id
|
||||
)
|
||||
expect(updatedUserPersonalization?.fields).to.eql(newFields)
|
||||
@ -128,7 +119,7 @@ describe('User Personalization API', () => {
|
||||
|
||||
after(async () => {
|
||||
// clean up
|
||||
await deleteUserPersonalization(existingUserPersonalization.id, user.id)
|
||||
await deleteUserPersonalization(user.id)
|
||||
})
|
||||
|
||||
const query = `
|
||||
@ -150,10 +141,9 @@ describe('User Personalization API', () => {
|
||||
it('returns the user personalization', async () => {
|
||||
const res = await graphqlRequest(query, authToken).expect(200)
|
||||
|
||||
expect(res.body.data.getUserPersonalization.userPersonalization).to.eql({
|
||||
id: existingUserPersonalization.id,
|
||||
fields: existingUserPersonalization.fields,
|
||||
})
|
||||
expect(
|
||||
res.body.data.getUserPersonalization.userPersonalization.fields
|
||||
).to.eql(existingUserPersonalization.fields)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user