Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement!: create should send 201 status code #19869

Merged
merged 28 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
34887c3
enhancement: log when server restarts
innerdvations Mar 21, 2024
132abdf
enhancement: ignore log files in develop watch
innerdvations Mar 21, 2024
d6ffccc
enhancement: log event when strapi starts up
innerdvations Mar 21, 2024
b838503
enhancement: put the logs in the right place
innerdvations Mar 21, 2024
3204de4
revert: line break
innerdvations Mar 21, 2024
33cb837
chore: remove word server from logging
innerdvations Mar 21, 2024
33e0a48
fix: send 201 created status code on create
innerdvations Mar 21, 2024
8c11ce8
Merge branch 'v5/main' into fix/create-status-201
innerdvations Mar 21, 2024
370de35
test: update expected status code in tests
innerdvations Mar 21, 2024
5cf88d9
Merge branch 'v5/main' into fix/create-status-201
innerdvations Mar 21, 2024
00de0c2
Merge branch 'v5/main' into fix/create-status-201
innerdvations Apr 10, 2024
7df9e7c
test: expect 201 status for create
innerdvations Apr 11, 2024
8c97455
Merge branch 'v5/main' into fix/create-status-201
innerdvations Apr 11, 2024
c37016b
test: expect 201 status for create
innerdvations Apr 11, 2024
481cded
fix: send 201 status for file upload create
innerdvations Apr 11, 2024
06d79cd
Merge branch 'v5/main' into fix/create-status-201
innerdvations Apr 11, 2024
077210e
test: expect 201 status for create
innerdvations Apr 11, 2024
9a5baa0
fix: send 201 status for new uploads
innerdvations Apr 11, 2024
6385591
test: upload expect 201
innerdvations Apr 11, 2024
e83d720
test: expect 201 for create
innerdvations Apr 11, 2024
c3b9e01
Merge branch 'v5/main' into fix/create-status-201
innerdvations Apr 12, 2024
e8d7215
fix: revert data shape
innerdvations Apr 12, 2024
14a0a27
test: expect 201 for create
innerdvations Apr 12, 2024
920ae1f
fix: send correct data shape
innerdvations Apr 12, 2024
27500a7
test: fix test data shape
innerdvations Apr 12, 2024
7c86120
Merge branch 'v5/main' into fix/create-status-201
innerdvations Apr 12, 2024
bbb7406
test: fix test
innerdvations Apr 12, 2024
40ea3b8
test: rw expect 201 for create
innerdvations Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export default {
]);

const sanitizedDocument = await permissionChecker.sanitizeOutput(document);
ctx.status = 201;
ctx.body = await documentMetadata.formatDocumentWithMetadata(model, sanitizedDocument, {
// Empty metadata as it's not relevant for a new document
availableLocales: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('Release Action controller', () => {
params: {
releaseId: 1,
},
created: jest.fn(),
request: {
body: [
{
Expand All @@ -123,9 +124,18 @@ describe('Release Action controller', () => {
await releaseActionController.createMany(ctx);

expect(mockCreateAction).toHaveBeenCalledTimes(2);
expect(ctx.body.data).toHaveLength(2);
expect(ctx.body.meta.totalEntries).toBe(2);
expect(ctx.body.meta.entriesAlreadyInRelease).toBe(0);

expect(ctx.created).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.any(Array), // Ensure data is an array
meta: expect.objectContaining({
totalEntries: 2,
entriesAlreadyInRelease: 0,
}),
})
);
const firstCallArgument = ctx.created.mock.calls[0][0];
expect(firstCallArgument.data.length).toBe(2);
});

it('should count already added entries and dont throw an error', async () => {
Expand All @@ -139,6 +149,7 @@ describe('Release Action controller', () => {
params: {
releaseId: 1,
},
created: jest.fn(),
request: {
body: [
{
Expand All @@ -155,9 +166,10 @@ describe('Release Action controller', () => {
await releaseActionController.createMany(ctx);

expect(mockCreateAction).toHaveBeenCalledTimes(1);
expect(ctx.body.data).toHaveLength(0);
expect(ctx.body.meta.totalEntries).toBe(1);
expect(ctx.body.meta.entriesAlreadyInRelease).toBe(1);
expect(ctx.created).toHaveBeenCalledWith({
data: [],
meta: { totalEntries: 1, entriesAlreadyInRelease: 1 },
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const releaseActionController = {
const releaseService = getService('release', { strapi });
const releaseAction = await releaseService.createAction(releaseId, releaseActionArgs);

ctx.body = {
ctx.created({
data: releaseAction,
};
});
},

async createMany(ctx: Koa.Context) {
Expand Down Expand Up @@ -64,13 +64,13 @@ const releaseActionController = {

const newReleaseActions = releaseActions.filter((action) => action !== null);

ctx.body = {
ctx.created({
data: newReleaseActions,
meta: {
entriesAlreadyInRelease: releaseActions.length - newReleaseActions.length,
totalEntries: releaseActions.length,
},
};
});
},

async findMany(ctx: Koa.Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ const releaseController = {
model: RELEASE_MODEL_UID,
});

ctx.body = {
data: await permissionsManager.sanitizeOutput(release),
};
ctx.created({
body: {
data: await permissionsManager.sanitizeOutput(release),
},
});
},

async update(ctx: Koa.Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const createCollectionTypeController = ({

const sanitizedEntity = await this.sanitizeOutput(entity, ctx);

ctx.status = 201;
return this.transformResponse(sanitizedEntity);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export default {
})
.then(formatWorkflowToAdmin);

ctx.body = {
ctx.created({
data: await sanitizeOutput(createdWorkflow),
};
});
},

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/core/upload/server/src/controllers/admin-folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export default {
model: FOLDER_MODEL_UID,
});

ctx.body = {
ctx.created({
data: await permissionsManager.sanitizeOutput(folder),
};
});
},

async update(ctx: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default {
const signedFiles = await async.map(uploadedFiles, getService('file').signFileUrls);

ctx.body = await pm.sanitizeOutput(signedFiles, { action: ACTIONS.read });
ctx.status = 201;
jhoward1994 marked this conversation as resolved.
Show resolved Hide resolved
},

// TODO: split into multiple endpoints
Expand Down
1 change: 1 addition & 0 deletions packages/core/upload/server/src/controllers/content-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => {
});

ctx.body = await sanitizeOutput(uploadedFiles as any, ctx);
ctx.status = 201;
},

// TODO: split into multiple endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('CM API - Basic + compo', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
expect(res.body.data.publishedAt).toBeDefined();
data.productsWithCompo.push(res.body.data);
Expand Down
2 changes: 1 addition & 1 deletion tests/api/core/content-manager/api/basic-compo.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('CM API - Basic + compo', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
expect(res.body.data.publishedAt).toBeDefined();
data.productsWithCompo.push(res.body.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('CM API - Basic + compo', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
expect(res.body.data.publishedAt).toBeNull();
data.productsWithCompoAndDP.push(res.body.data);
Expand Down
8 changes: 4 additions & 4 deletions tests/api/core/content-manager/api/basic-dp-compo.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('CM API - Basic + compo', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
expect(res.body.data.publishedAt).toBeNull();
data.productsWithCompoAndDP.push(res.body.data);
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('CM API - Basic + compo', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
data.productsWithCompoAndDP.push(res.body.data);
});
Expand All @@ -160,7 +160,7 @@ describe('CM API - Basic + compo', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
data.productsWithCompoAndDP.push(res.body.data);
});
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('CM API - Basic + compo', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
data.productsWithCompoAndDP.push(res.body.data);
});
Expand Down
8 changes: 4 additions & 4 deletions tests/api/core/content-manager/api/basic-dp-dz.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('CM API - Basic + dz', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
expect(res.body.data.publishedAt).toBeNull();
data.productsWithDzAndDP.push(res.body.data);
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('CM API - Basic + dz', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(method === 'create' ? 201 : 200);
expect(res.body.data).toMatchObject(product);
data.productsWithDzAndDP.push(res.body.data);
});
Expand All @@ -206,7 +206,7 @@ describe('CM API - Basic + dz', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(method === 'create' ? 201 : 200);
expect(res.body.data).toMatchObject(product);
data.productsWithDzAndDP.push(res.body.data);
});
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('CM API - Basic + dz', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(method === 'create' ? 201 : 200);
expect(res.body.data).toMatchObject(product);
data.productsWithDzAndDP.push(res.body.data);
});
Expand Down
8 changes: 4 additions & 4 deletions tests/api/core/content-manager/api/basic-dp.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('CM API - Basic', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
expect(res.body.data.publishedAt).toBeNull();
data.productsWithDP.push(res.body.data);
Expand All @@ -91,7 +91,7 @@ describe('CM API - Basic', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(_.omit(product, 'publishedAt'));
expect(res.body.data.publishedAt).toBeNull();
data.productsWithDP.push(res.body.data);
Expand Down Expand Up @@ -409,7 +409,7 @@ describe('CM API - Basic', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
data.productsWithDP.push(res.body.data);
});
Expand All @@ -424,7 +424,7 @@ describe('CM API - Basic', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject({
...product,
});
Expand Down
2 changes: 1 addition & 1 deletion tests/api/core/content-manager/api/basic-dz.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('CM API - Basic + dz', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(product);
expect(res.body.data.publishedAt).toBe(null);
data.productsWithDz.push(res.body.data);
Expand Down
2 changes: 1 addition & 1 deletion tests/api/core/content-manager/api/basic.test.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('CM API - Basic', () => {
body: product,
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject(omit('hiddenAttribute', product));
expect(res.body.data).not.toHaveProperty('hiddenAttribute');
expect(res.body.data.publishedAt).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(Array.isArray(res.body.data.field)).toBe(true);
expect(res.body.data.field).toEqual(
expect.arrayContaining([
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
});

test('Throws when sending too many items', async () => {
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data.field).toEqual([]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(Array.isArray(res.body.data.field)).toBe(true);
expect(res.body.data.field).toEqual(
expect.arrayContaining([
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data.field).toEqual([]);
});

Expand All @@ -108,7 +108,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(res.body.data.field).toEqual([]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(Array.isArray(res.body.data.field)).toBe(true);
expect(res.body.data.field).toEqual(
expect.arrayContaining([
Expand All @@ -89,7 +89,7 @@ describe('Non repeatable and Not required component', () => {
},
});

expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
expect(Array.isArray(res.body.data.field)).toBe(true);
expect(res.body.data.field).toEqual(
expect.arrayContaining([
Expand Down