feat: add upsert to database interface and adapters (#8397)
- Adds the upsert method to the database interface - Adds a mongodb specific option to extend the updateOne to accept mongoDB Query Options (to pass `upsert: true`) - Added upsert method to all database adapters - Uses db.upsert in the payload preferences update operation Includes a test using payload-preferences
This commit is contained in:
@@ -101,7 +101,7 @@ describe('Auth', () => {
|
||||
|
||||
describe('logged in', () => {
|
||||
let token: string | undefined
|
||||
let loggedInUser: User | undefined
|
||||
let loggedInUser: undefined | User
|
||||
|
||||
beforeAll(async () => {
|
||||
const response = await restClient.POST(`/${slug}/login`, {
|
||||
@@ -396,6 +396,52 @@ describe('Auth', () => {
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should only have one preference per user per key', async () => {
|
||||
await restClient.POST(`/payload-preferences/${key}`, {
|
||||
body: JSON.stringify({
|
||||
value: { property: 'test', property2: 'test' },
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `JWT ${token}`,
|
||||
},
|
||||
})
|
||||
await restClient.POST(`/payload-preferences/${key}`, {
|
||||
body: JSON.stringify({
|
||||
value: { property: 'updated', property2: 'updated' },
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `JWT ${token}`,
|
||||
},
|
||||
})
|
||||
|
||||
const result = await payload.find({
|
||||
collection: 'payload-preferences',
|
||||
depth: 0,
|
||||
where: {
|
||||
and: [
|
||||
{
|
||||
key: { equals: key },
|
||||
},
|
||||
{
|
||||
'user.relationTo': {
|
||||
equals: 'users',
|
||||
},
|
||||
},
|
||||
{
|
||||
'user.value': {
|
||||
equals: loggedInUser.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.docs[0].value.property).toStrictEqual('updated')
|
||||
expect(result.docs[0].value.property2).toStrictEqual('updated')
|
||||
|
||||
expect(result.docs).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should delete', async () => {
|
||||
const response = await restClient.DELETE(`/payload-preferences/${key}`, {
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user