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

Code before:
          payload.update({
            locale: 'es',
            collection: 'indexed-fields',
            data: { localizedUniqueRequiredText: '30' },
            id: doc.id,
          }),
        )

      await expect(
        payload.create({
          collection: 'indexed-fields',
          data: {
            localizedUniqueRequiredText: '4',
            text: '5',
            uniqueRequiredText: '10',
            uniqueHasManyRelationship: [textDoc.id],
          },
        }),
      ).rejects.toBeTruthy()
    })

    it('should throw validation error saving on unique relationship fields polymorphic not hasMany', async () => {
      const textDoc = await payload.create({ collection: 'text-fields', data: { text: 'asd' } })

      await payload
        .create({
          collection: 'indexed-fields',
          data: {
            localizedUniqueRequiredText: '1',
            text: '2',
            uniqueRequiredText: '3',
            uniquePolymorphicRelationship: { relationTo: 'text-fields', value: textDoc.id },
          },
        })
        // Skip mongodb unique error because it threats localizedUniqueRequriedText.es as undefined
        .then((doc) =>
          payload.update({
            locale: 'es',
            collection: 'indexed-fields',
            data: { localizedUniqueRequiredText: '20' },
            id: doc.id,
          }),
        )

      // Should allow the same relationship on a diferrent field!
      await payload
        .create({
          collection: 'indexed-fields',
          data: {
            localizedUniqueRequiredText: '31',
            text: '24',

Review comment (suggestion):
One suggestion: in vitest, you can get the current test name via `task.name`. If you hash that, you can get a per-test unique string and never have to worry about `unique-hasMany(n)` colliding with another string in another test.

Code after:
        }),
      ).rejects.toBeTruthy()
    })

    it('should throw validation error saving on unique relationship fields hasMany: true', async () => {
      const textDoc = await payload.create({
        collection: 'text-fields',
        data: { text: 'unique-test-hasMany-true-' + Date.now() },
      })

      const firstDoc = await payload
        .create({
          collection: 'indexed-fields',
          data: {
            localizedUniqueRequiredText: 'unique-hasMany1-' + Date.now(),
            text: 'unique-hasMany2-' + Date.now(),
            uniqueRequiredText: 'unique-hasMany3-' + Date.now(),
            uniqueHasManyRelationship: [textDoc.id],
          },
        })
        // Skip mongodb unique error because it threats localizedUniqueRequriedText.es as undefined
        .then((doc) =>
          payload.update({
            locale: 'es',
            collection: 'indexed-fields',
            data: { localizedUniqueRequiredText: 'unique-hasMany40-' + Date.now() },
            id: doc.id,
          }),
        )

      // Should allow the same relationship on a diferrent field!
      const secondDoc = await payload
        .create({
          collection: 'indexed-fields',
          data: {
            localizedUniqueRequiredText: 'unique-hasMany31-' + Date.now(),
            text: 'unique-hasMany24-' + Date.now(),
            uniqueRequiredText: 'unique-hasMany55-' + Date.now(),
            uniqueHasManyRelationship_2: [textDoc.id],
          },
        })
        // Skip mongodb unique error because it threats localizedUniqueRequriedText.es as undefined
        .then((doc) =>
          payload.update({
            locale: 'es',
            collection: 'indexed-fields',
            data: { localizedUniqueRequiredText: 'unique-hasMany30-' + Date.now() },
            id: doc.id,
          }),
        )