Repository: strapi/strapi
File: tests/api/core/strapi/document-service/update.test.api.ts (TypeScript)

Code before:
        documentId: articleDb.documentId,
        data: { title: 'Updated Document' },
        status: 'published',
      });

      expect(article).toMatchObject({
        title: 'Updated Document',
        publishedAt: expect.any(String),
      });
    });

    testInTransaction('Returns null if document to update does not exist', async () => {
      const article = await updateArticle({
        documentId: 'does-not-exist',
        data: { title: 'updated document' },
      });

      expect(article).toBeNull();
    });

    testInTransaction(
      'Preserves non-localized fields when updating localized content for new locale',
      async () => {
        // This test covers the fix for bug #21594: https://github.com/strapi/strapi/issues/21594
        // When updating a content type with both localized and non-localized fields,
        // updating only the localized field for a new locale should preserve the non-localized fields

        const MIXED_CONTENT_UID = 'api::mixed-content.mixed-content';

        // Create a document with both localized and non-localized fields
        const originalDoc = await strapi.documents(MIXED_CONTENT_UID).create({
          data: {
            localizedText: 'Original Text',
            sharedText: 'Shared Content',
          },
          locale: 'en',
        });

        const updatedDoc = await strapi.documents(MIXED_CONTENT_UID).update({
          documentId: originalDoc.documentId,
          locale: 'es',
          data: {
            localizedText: 'Texto Español',
          },
        });

        expect(updatedDoc).toMatchObject({
          documentId: originalDoc.documentId,
          locale: 'es',
          localizedText: 'Texto Español',
          // Non-localized field should remain unchanged

Review comment (suggestion):
```suggestion
        // Covers issue https://github.com/strapi/strapi/issues/21594
```

Code after:
        documentId: articleDb.documentId,
        data: { title: 'Updated Document' },
        status: 'published',
      });

      expect(article).toMatchObject({
        title: 'Updated Document',
        publishedAt: expect.any(String),
      });
    });

    testInTransaction('Returns null if document to update does not exist', async () => {
      const article = await updateArticle({
        documentId: 'does-not-exist',
        data: { title: 'updated document' },
      });

      expect(article).toBeNull();
    });

    testInTransaction(
      'Preserves non-localized fields when updating localized content for new locale',
      async () => {
        // Covers issue https://github.com/strapi/strapi/issues/21594

        const MIXED_CONTENT_UID = 'api::mixed-content.mixed-content';

        // Create a document with both localized and non-localized fields
        const originalDoc = await strapi.documents(MIXED_CONTENT_UID).create({
          data: {
            localizedText: 'Original Text',
            sharedText: 'Shared Content',
          },
          locale: 'en',
        });

        const updatedDoc = await strapi.documents(MIXED_CONTENT_UID).update({
          documentId: originalDoc.documentId,
          locale: 'es',
          data: {
            localizedText: 'Texto Español',
          },
        });

        expect(updatedDoc).toMatchObject({
          documentId: originalDoc.documentId,
          locale: 'es',
          localizedText: 'Texto Español',
          // Non-localized field should remain unchanged
          sharedText: 'Shared Content',
        });