diff --git a/.changeset/angry-points-bow.md b/.changeset/angry-points-bow.md new file mode 100644 index 00000000..5d6aea35 --- /dev/null +++ b/.changeset/angry-points-bow.md @@ -0,0 +1,5 @@ +--- +"strapi-plugin-webtools": patch +--- + +fix: response structure for cloned content to prevent issues diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c09313dd..bb5ee2bc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,13 +58,7 @@ jobs: run: yarn playground:install - name: Build the playground run: yarn playground:build - # We allow the unit tests to fail the first time around. - # For some reason they always fail the first time. - - name: Run unit tests (allow failures) - run: yarn test:unit || exit 0 - # Then we run the test again, but this time we disallow failures. - # This way we can see the actual error messages. - - name: Run unit tests (disallow failures) + - name: Run unit tests run: yarn test:unit - name: Run integration tests run: yarn test:integration diff --git a/packages/core/server/middlewares/__tests__/middlewares.test.js b/packages/core/server/middlewares/__tests__/middlewares.test.js index 4f18bc9a..2e69c9ae 100644 --- a/packages/core/server/middlewares/__tests__/middlewares.test.js +++ b/packages/core/server/middlewares/__tests__/middlewares.test.js @@ -29,11 +29,11 @@ describe('Query layer decorator', () => { expect(clonedPage).not.toBeNull(); const newUrlAliasPath = `${page.url_alias[0].url_path}-0`; - expect(clonedPage).toHaveProperty('url_alias[0].url_path', newUrlAliasPath); - expect(clonedPage).toHaveProperty('url_alias[0].generated', true); - expect(clonedPage).toHaveProperty('url_alias[0].contenttype', 'api::test.test'); + expect(clonedPage).toHaveProperty('entries[0].url_alias[0].url_path', newUrlAliasPath); + expect(clonedPage).toHaveProperty('entries[0].url_alias[0].generated', true); + expect(clonedPage).toHaveProperty('entries[0].url_alias[0].contenttype', 'api::test.test'); expect(clonedPage.documentId).not.toBe(page.documentId); - expect(clonedPage.url_alias[0].documentId).not.toBe(page.url_alias[0].documentId); + expect(clonedPage.entries[0].url_alias[0].documentId).not.toBe(page.url_alias[0].documentId); }); it('Create - Should generate a new URL alias', async () => { diff --git a/packages/core/server/middlewares/generate-url-alias.ts b/packages/core/server/middlewares/generate-url-alias.ts index 4ef7124d..936c34a9 100644 --- a/packages/core/server/middlewares/generate-url-alias.ts +++ b/packages/core/server/middlewares/generate-url-alias.ts @@ -154,6 +154,13 @@ const generateUrlAliasMiddleware: Modules.Documents.Middleware.Middleware = asyn populate: params.populate, }); + if (action === 'clone') { + return { + documentId: entity.documentId, + entries: [finalEntity], + }; + } + return finalEntity; };