mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add an extra test for clearing the user personalization data
This commit is contained in:
parent
bbf3de1f86
commit
2cb1b8ed1e
2 changed files with 45 additions and 3 deletions
|
|
@ -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']
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue