Repository: payloadcms/payload
File: test/database/int.spec.ts (TypeScript)

Code before:
      collection: postsSlug,
      data: {
        title: 'some-title-here',
      },
      req: {},
      where: {
        title: {
          equals: 'some-title-here',
        },
      },
    })

    // Should stay the same ID
    expect(postShouldCreated.id).toBe(postShouldUpdated.id)
  })

  it('should enforce unique ids on db level even after delete', async () => {
    const { id } = await payload.create({ collection: postsSlug, data: { title: 'ASD' } })
    await payload.delete({ id, collection: postsSlug })
    const { id: id_2 } = await payload.create({ collection: postsSlug, data: { title: 'ASD' } })
    expect(id_2).not.toBe(id)
  })

  it('payload.db.createGlobal should have globalType, updatedAt, createdAt fields', async () => {
    const timestamp = Date.now()
    let result = (await payload.db.createGlobal({
      slug: 'global-2',
      data: { text: 'this is global-2' },
    })) as { globalType: string } & Global2

    expect(result.text).toBe('this is global-2')
    expect(result.globalType).toBe('global-2')
    expect(timestamp).toBeLessThanOrEqual(new Date(result.createdAt as string).getTime())
    expect(timestamp).toBeLessThanOrEqual(new Date(result.updatedAt as string).getTime())

    const createdAt = new Date(result.createdAt as string).getTime()

    result = (await payload.db.updateGlobal({
      slug: 'global-2',
      data: { text: 'this is global-2 but updated' },
    })) as { globalType: string } & Global2

    expect(result.text).toBe('this is global-2 but updated')
    expect(result.globalType).toBe('global-2')
    expect(createdAt).toEqual(new Date(result.createdAt as string).getTime())
    expect(createdAt).toBeLessThan(new Date(result.updatedAt as string).getTime())
  })

  it('payload.updateGlobal should have globalType, updatedAt, createdAt fields', async () => {
    const timestamp = Date.now()
    let result = (await payload.updateGlobal({

Review comment (bug):
I realized in CI that this test doesn't just fail for content-api, but also for our Postgres DB adapter, although apparently for a different reason:

```
- Expected: 
{
  "coordinates": [
    10,
    20,
  ],
  "type": "Point",
}

+ Received: 
[
  10,
  20,
]

 ❯ test/database/int.spec.ts:3683:27
    3681|     expect(updated.defaultValue).toBe('custom value')
    3682|     expect(updated.select).toBe('option0')
    3683|     expect(updated.point).toStrictEqual({ type: 'Point', coordinates: …
       |                           ^
    3684| 
    3685|     // Third upsert (UPDATE) with partial data: should NOT apply defau…
```

I've already created tasks in Linear to track this:

https://linear.app/figma-trial/issue/PAYL-789/fix-test-should-apply-default-values-on-upsert-insert-but-not-on

https://linear.app/figma-trial/issue/PAYL-790/fix-test-should-apply-default-values-on-upsert-insert-but-not-on

Code after:
    })

    expect(postShouldCreated).toBeTruthy()

    const postShouldUpdated = await payload.db.upsert({
      collection: postsSlug,
      data: {
        title: 'some-title-here',
      },
      req: {},
      where: {
        title: {
          equals: 'some-title-here',
        },
      },
    })

    // Should stay the same ID
    expect(postShouldCreated.id).toBe(postShouldUpdated.id)
  })

  it('should apply default values on upsert insert but not on update', async () => {
    // TODO: remove this as soon as It's fixed in the other database adapters
    if (payload.db.name !== 'mongoose') {
      return
    }
    // First upsert (INSERT): should apply defaults
    const inserted = await payload.db.upsert({
      collection: defaultValuesSlug,
      data: {
        title: 'upsert-test',
        // Don't pass defaultValue field - should be auto-applied
      },
      req: {},
      where: {
        title: {
          equals: 'upsert-test',
        },
      },
    })

    // Defaults should be applied on insert
    expect(inserted.defaultValue).toBe('default value from database')
    expect(inserted.select).toBe('default')
    expect(inserted.point).toStrictEqual({ type: 'Point', coordinates: [10, 20] })

    // Second upsert (UPDATE): should NOT overwrite existing values with defaults
    const updated = await payload.db.upsert({
      collection: defaultValuesSlug,
      data: {
        title: 'upsert-test',