test(api): enable graphl and upload tests (#21500)

This commit is contained in:
Ben Irvin 2024-10-01 11:31:13 +02:00 committed by GitHub
parent 3fed37db71
commit 1a60292e6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 53 deletions

View File

@ -39,7 +39,7 @@ const createAFile = async (parent = null) => {
return res.body[0];
};
describe.skip('Folder', () => {
describe('Folder', () => {
const builder = createTestBuilder();
beforeAll(async () => {
@ -274,7 +274,7 @@ describe.skip('Folder', () => {
});
expect(res.body.data).toMatchObject({
name: 'new name',
name: 'new name folder',
path: folder.path,
});
data.folders.push(res.body.data);

View File

@ -165,13 +165,13 @@ describe('Uploads folder', () => {
});
});
describe.skip('Attach to an entity', () => {
describe('Attach to an entity', () => {
beforeAll(async () => {
const res = await rq({
const res = await rqAdmin({
url: '/content-manager/collection-types/api::dog.dog',
method: 'POST',
url: '/dogs',
formData: {
data: '{}',
body: {
name: 'dog',
},
});
data.dogs.push(res.body.data);
@ -190,7 +190,7 @@ describe('Uploads folder', () => {
},
});
expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
const { body: file } = await rqAdmin({
method: 'GET',
@ -199,7 +199,7 @@ describe('Uploads folder', () => {
expect(file).toMatchObject({
folder: {
name: 'API Uploads (2)',
name: 'API Uploads (1)',
pathId: expect.any(Number),
},
folderPath: `/${file.folder.pathId}`,
@ -229,7 +229,7 @@ describe('Uploads folder', () => {
},
});
expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
const { body: file } = await rqAdmin({
method: 'GET',
@ -238,7 +238,7 @@ describe('Uploads folder', () => {
expect(file).toMatchObject({
folder: {
name: 'API Uploads (2)',
name: 'API Uploads (1)',
pathId: expect.any(Number),
},
folderPath: `/${file.folder.pathId}`,
@ -252,7 +252,7 @@ describe('Uploads folder', () => {
method: 'POST',
url: '/upload/actions/bulk-delete',
body: {
folderIds: [uploadFolder.id],
folderIds: [uploadFolder.documentId],
},
});
@ -260,7 +260,7 @@ describe('Uploads folder', () => {
method: 'POST',
url: '/upload/folders',
body: {
name: 'API Uploads (2)',
name: 'API Uploads (1)',
parent: null,
},
});
@ -276,7 +276,7 @@ describe('Uploads folder', () => {
},
});
expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(201);
const { body: file } = await rqAdmin({
method: 'GET',
@ -285,7 +285,7 @@ describe('Uploads folder', () => {
expect(file).toMatchObject({
folder: {
name: 'API Uploads (3)',
name: 'API Uploads (1)',
pathId: expect.any(Number),
},
folderPath: `/${file.folder.pathId}`,

View File

@ -346,7 +346,10 @@ describe('Test Graphql API End to End', () => {
});
});
test.skip('List posts with `createdBy` and `updatedBy`', async () => {
// This has not been enabled because it does not seem to work and the v5 docs says the feature is missing, but it should be added
test.todo(`updatedBy and createdBy are available with populateCreatorFields`);
test('`updatedBy` is not available', async () => {
const res = await graphqlQuery({
query: /* GraphQL */ `
{
@ -358,6 +361,7 @@ describe('Test Graphql API End to End', () => {
bigint
nullable
category
updatedBy
}
}
}
@ -365,13 +369,30 @@ describe('Test Graphql API End to End', () => {
`,
});
expect(res.statusCode).toBe(200);
expect(res.statusCode).toBe(400);
});
// no errors should be present in the response
expect(res.body.error).toBeUndefined();
test('`createdBy` is not available', async () => {
const res = await graphqlQuery({
query: /* GraphQL */ `
{
posts_connection(start: 1) {
data {
documentId
attributes {
name
bigint
nullable
category
createdBy
}
}
}
}
`,
});
// since the posts are created without AdminUser, it should return null
expect(res.body.data.posts_connection[0].createdBy).toBeNull();
expect(res.statusCode).toBe(400);
});
test.each([

View File

@ -145,22 +145,6 @@ describe('i18n - Content API', () => {
expect(body.data).toHaveLength(1);
expect(body.data[0]).toMatchObject(transformToRESTResource(data.categories[1]));
});
test.skip('Can filter on all locale', async () => {
const res = await rq({
method: 'GET',
url: '/categories?locale=all',
});
const { statusCode, body } = res;
expect(statusCode).toBe(200);
expect(Array.isArray(body.data)).toBe(true);
expect(body.data).toHaveLength(2);
expect(body.data).toEqual(
expect.arrayContaining(data.categories.map((category) => transformToRESTResource(category)))
);
});
});
describe('Test single type', () => {
@ -187,18 +171,5 @@ describe('i18n - Content API', () => {
expect(statusCode).toBe(200);
expect(body.data).toMatchObject(transformToRESTResource(data.homepages[1]));
});
// TODO V5: Decide if we want to support locale=all
test.skip('Can filter on all locale', async () => {
const res = await rq({
method: 'GET',
url: '/homepage?locale=all',
});
const { statusCode, body } = res;
expect(statusCode).toBe(200);
expect(body.data).toMatchObject(transformToRESTResource(data.homepages));
});
});
});

View File

@ -5,7 +5,7 @@ const { createRequest, createAuthRequest } = require('api-tests/request');
const { createTestBuilder } = require('api-tests/builder');
// Test a simple default API with no relations
describe.skip('Simple Test GraphQL Users API End to End', () => {
describe('Simple Test GraphQL Users API End to End', () => {
let strapi;
let rq;
let graphqlQuery;
@ -189,7 +189,7 @@ describe.skip('Simple Test GraphQL Users API End to End', () => {
});
// Test with attributes such as components, relations..
describe.skip('Advanced Test GraphQL Users API End to End', () => {
describe('Advanced Test GraphQL Users API End to End', () => {
const builder = createTestBuilder();
let strapi;
@ -335,7 +335,12 @@ describe.skip('Advanced Test GraphQL Users API End to End', () => {
await restart();
});
describe('Test register and login with component', () => {
/**
* This is no longer allowed for security reasons
* We only have register.allowedFields to allow fields to be submitted on registration
* TODO: add update.allowedFields feature and re-enable
* */
describe.skip('Test register and login with component', () => {
test('Register a user', async () => {
const res = await graphqlQuery({
query: /* GraphQL */ `