Add an extra test for clearing the user personalization data

This commit is contained in:
Jackson Harper 2024-05-15 10:35:58 +08:00
parent bbf3de1f86
commit 2cb1b8ed1e
2 changed files with 45 additions and 3 deletions

View file

@ -17,14 +17,19 @@ export const setUserPersonalizationResolver = authorized<
MutationSetUserPersonalizationArgs
>(async (_, { input }, { authTrx, uid }) => {
const newValues = input as Omit<SetUserPersonalizationInput, 'digestConfig'>
const digestValues = input.digestConfig
? {
digestConfig: () => {
return JSON.stringify(input.digestConfig)
},
}
: {}
const result = await authTrx(async (t) => {
return t.getRepository(UserPersonalization).upsert(
{
user: { id: uid },
...newValues,
digestConfig: () => {
return JSON.stringify(input.digestConfig)
},
...digestValues,
},
['user']
)

View file

@ -102,6 +102,43 @@ describe('User Personalization API', () => {
)
expect(updatedUserPersonalization?.fields).to.eql(newFields)
})
it('updates and can clear the user personalization', async () => {
const newFields = {
channels: ['push', 'email'],
}
const res = await graphqlRequest(query, authToken, {
input: { fields: newFields },
}).expect(200)
expect(
res.body.data.setUserPersonalization.updatedUserPersonalization.fields
).to.eql(newFields)
const updatedUserPersonalization = await findUserPersonalization(
user.id
)
expect(updatedUserPersonalization?.fields).to.eql(newFields)
const updatedFields = {
channels: ['push', 'email'],
}
const updatedRes = await graphqlRequest(query, authToken, {
input: { fields: updatedFields },
}).expect(200)
expect(
updatedRes.body.data.setUserPersonalization.updatedUserPersonalization
.fields
).to.eql(updatedFields)
const updatedUserPersonalization2 = await findUserPersonalization(
user.id
)
expect(updatedUserPersonalization2?.fields).to.eql(newFields)
})
})
})