2020-08-21 16:19:11 +02:00
|
|
|
'use strict';
|
|
|
|
|
2019-03-09 01:06:39 +01:00
|
|
|
// Helpers.
|
2019-05-06 15:33:25 +02:00
|
|
|
const { registerAndLogin } = require('../../../test/helpers/auth');
|
|
|
|
const createModelsUtils = require('../../../test/helpers/models');
|
2019-03-09 01:06:39 +01:00
|
|
|
const form = require('../../../test/helpers/generators');
|
2019-05-06 17:27:24 +02:00
|
|
|
const { createAuthRequest } = require('../../../test/helpers/request');
|
2019-03-09 01:06:39 +01:00
|
|
|
|
|
|
|
const cleanDate = entry => {
|
|
|
|
delete entry.updatedAt;
|
|
|
|
delete entry.createdAt;
|
|
|
|
delete entry.created_at;
|
|
|
|
delete entry.updated_at;
|
|
|
|
};
|
|
|
|
|
|
|
|
let data;
|
2019-05-06 15:33:25 +02:00
|
|
|
let modelsUtils;
|
2019-03-09 01:06:39 +01:00
|
|
|
let rq;
|
|
|
|
|
|
|
|
describe('Content Manager End to End', () => {
|
|
|
|
beforeAll(async () => {
|
2019-05-06 15:33:25 +02:00
|
|
|
const token = await registerAndLogin();
|
2019-05-06 17:27:24 +02:00
|
|
|
rq = createAuthRequest(token);
|
2019-03-09 01:06:39 +01:00
|
|
|
|
2019-05-06 15:33:25 +02:00
|
|
|
modelsUtils = createModelsUtils({ rq });
|
2019-03-09 01:06:39 +01:00
|
|
|
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.createContentTypes([
|
2019-05-06 15:33:25 +02:00
|
|
|
form.article,
|
|
|
|
form.tag,
|
|
|
|
form.category,
|
|
|
|
form.reference,
|
2019-07-09 09:25:22 +02:00
|
|
|
form.articlewithtag,
|
2019-05-06 15:33:25 +02:00
|
|
|
]);
|
|
|
|
}, 60000);
|
2019-03-09 01:06:39 +01:00
|
|
|
|
2019-05-06 17:27:24 +02:00
|
|
|
afterAll(
|
|
|
|
() =>
|
2020-08-27 18:11:16 +02:00
|
|
|
modelsUtils.deleteContentTypes(['article', 'tag', 'category', 'reference', 'articlewithtag']),
|
2019-05-06 17:27:24 +02:00
|
|
|
60000
|
|
|
|
);
|
2019-03-09 01:06:39 +01:00
|
|
|
|
2020-08-18 17:09:21 +02:00
|
|
|
describe('Content Types api', () => {
|
2020-02-11 09:56:15 +01:00
|
|
|
test('Label is pluralized', async () => {
|
|
|
|
const res = await rq({
|
2020-10-21 20:12:22 +02:00
|
|
|
url: `/content-manager/schemas/content-types`,
|
2020-02-11 09:56:15 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body.data).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
label: 'Articles',
|
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
|
|
|
label: 'Tags',
|
|
|
|
}),
|
|
|
|
expect.objectContaining({
|
|
|
|
label: 'Categories',
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-09 01:06:39 +01:00
|
|
|
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
data = {
|
|
|
|
articles: [],
|
|
|
|
tags: [],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create tag1', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::tag.tag',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'tag1',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
data.tags.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('tag1');
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create tag2', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::tag.tag',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'tag2',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
data.tags.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('tag2');
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create tag3', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::tag.tag',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'tag3',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
data.tags.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('tag3');
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create article1 without relation', async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 1',
|
|
|
|
content: 'My super content 1',
|
2019-08-05 15:22:39 +02:00
|
|
|
date: '2019-08-13T00:00:00.000Z',
|
2019-03-09 01:06:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
|
|
|
expect(body.tags.length).toBe(0);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2020-08-27 18:11:16 +02:00
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create article2 with tag1', async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 2',
|
|
|
|
content: 'Content 2',
|
|
|
|
tags: [data.tags[0]],
|
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
|
|
|
expect(body.tags.length).toBe(1);
|
|
|
|
expect(body.tags[0].id).toBe(data.tags[0].id);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2020-08-27 18:11:16 +02:00
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update article1 add tag2', async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
|
|
|
tags: [data.tags[1]],
|
|
|
|
});
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
|
|
|
expect(body.tags.length).toBe(1);
|
|
|
|
expect(body.tags[0].id).toBe(data.tags[1].id);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2020-08-27 18:11:16 +02:00
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update article1 add tag1 and tag3', async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0]);
|
|
|
|
entry.tags.push(data.tags[0]);
|
|
|
|
entry.tags.push(data.tags[2]);
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
|
|
|
expect(body.tags.length).toBe(3);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2020-08-27 18:11:16 +02:00
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update article1 remove one tag', async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0]);
|
|
|
|
entry.tags = entry.tags.slice(1);
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
|
|
|
expect(body.tags.length).toBe(2);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2020-08-27 18:11:16 +02:00
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update article1 remove all tag', async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
|
|
|
tags: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
|
|
|
expect(body.tags.length).toBe(0);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2020-08-27 18:11:16 +02:00
|
|
|
expect(body.published_at).toBeUndefined();
|
2020-08-21 19:13:02 +02:00
|
|
|
});
|
|
|
|
|
2019-03-09 01:06:39 +01:00
|
|
|
test('Delete all articles should remove the association in each tags related to them', async () => {
|
2019-03-12 11:58:30 +01:00
|
|
|
const { body: createdTag } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::tag.tag',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'tag11',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body: article12 } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
title: 'article12',
|
|
|
|
content: 'Content',
|
2019-03-12 11:58:30 +01:00
|
|
|
tags: [createdTag],
|
2019-03-09 01:06:39 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-03-12 11:58:30 +01:00
|
|
|
const { body: updatedTag } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::tag.tag/${createdTag.id}`,
|
2019-03-12 11:58:30 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
2019-03-09 01:06:39 +01:00
|
|
|
const { body: article13 } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
title: 'article13',
|
|
|
|
content: 'Content',
|
2019-03-12 11:58:30 +01:00
|
|
|
tags: [updatedTag],
|
2019-03-09 01:06:39 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const articles = [article12, article13];
|
|
|
|
|
|
|
|
expect(Array.isArray(articles[0].tags)).toBeTruthy();
|
|
|
|
expect(articles[0].tags.length).toBe(1);
|
|
|
|
expect(Array.isArray(articles[1].tags)).toBeTruthy();
|
|
|
|
expect(articles[1].tags.length).toBe(1);
|
|
|
|
|
|
|
|
let { body: tagToGet } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::tag.tag/${createdTag.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(Array.isArray(tagToGet.articles)).toBeTruthy();
|
|
|
|
expect(tagToGet.articles.length).toBe(2);
|
|
|
|
|
|
|
|
await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/deleteAll/application::article.article?${articles
|
2019-03-09 01:06:39 +01:00
|
|
|
.map((article, index) => `${index}=${article.id}`)
|
|
|
|
.join('&')}`,
|
|
|
|
method: 'DELETE',
|
|
|
|
});
|
|
|
|
|
|
|
|
let { body: tagToGet2 } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::tag.tag/${createdTag.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(Array.isArray(tagToGet2.articles)).toBeTruthy();
|
|
|
|
expect(tagToGet2.articles.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-08 17:34:56 +02:00
|
|
|
describe('Test manyWay articlesWithTags and tags', () => {
|
|
|
|
test('Creating an article with some many way tags', async () => {
|
|
|
|
const entry = {
|
|
|
|
tags: [data.tags[0]],
|
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-03-02 15:18:08 +01:00
|
|
|
url: '/content-manager/explorer/application::articlewithtag.articlewithtag',
|
2019-07-08 17:34:56 +02:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-07-08 17:34:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
|
|
|
expect(body.tags.length).toBe(1);
|
|
|
|
expect(body.tags[0].id).toBe(data.tags[0].id);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-07-08 17:34:56 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-09 01:06:39 +01:00
|
|
|
describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
data = {
|
|
|
|
articles: [],
|
|
|
|
categories: [],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create cat1', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::category.category',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'cat1',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
data.categories.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('cat1');
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create cat2', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::category.category',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'cat2',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
data.categories.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('cat2');
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create article1 with cat1', async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 1',
|
|
|
|
content: 'Content 1',
|
|
|
|
category: data.categories[0],
|
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(body.category.name).toBe(entry.category.name);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update article1 with cat2', async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
|
|
|
category: data.categories[1],
|
|
|
|
});
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(body.category.name).toBe(entry.category.name);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create article2', async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 2',
|
|
|
|
content: 'Content 2',
|
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update article2 with cat2', async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[1], {
|
|
|
|
category: data.categories[1],
|
|
|
|
});
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles[1] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(body.category.name).toBe(entry.category.name);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update cat1 with article1', async () => {
|
|
|
|
const entry = Object.assign({}, data.categories[0]);
|
|
|
|
entry.articles.push(data.articles[0]);
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::category.category/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.categories[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.articles.length).toBe(1);
|
|
|
|
expect(body.name).toBe(entry.name);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create cat3 with article1', async () => {
|
|
|
|
const entry = {
|
|
|
|
name: 'cat3',
|
|
|
|
articles: [data.articles[0]],
|
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::category.category',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.categories.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.articles.length).toBe(1);
|
|
|
|
expect(body.name).toBe(entry.name);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Get article1 with cat3', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${data.articles[0].id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.category.id).toBe(data.categories[2].id);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Get article2 with cat2', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${data.articles[1].id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.category.id).toBe(data.categories[1].id);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Get cat1 without relations', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::category.category/${data.categories[0].id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.articles.length).toBe(0);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Get cat2 with article2', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::category.category/${data.categories[1].id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.articles.length).toBe(1);
|
|
|
|
expect(body.articles[0].id).toBe(data.articles[1].id);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Get cat3 with article1', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::category.category/${data.categories[2].id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.articles.length).toBe(1);
|
|
|
|
expect(body.articles[0].id).toBe(data.articles[0].id);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Test oneToOne relation (article - reference) with Content Manager', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
data = {
|
|
|
|
articles: [],
|
|
|
|
references: [],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create ref1', async () => {
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::reference.reference',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'ref1',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
data.references.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.name).toBe('ref1');
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create article1', async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 1',
|
|
|
|
content: 'Content 1',
|
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2020-08-27 18:11:16 +02:00
|
|
|
expect(body.published_at).toBeUndefined();
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update article1 with ref1', async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
|
|
|
reference: data.references[0].id,
|
|
|
|
});
|
|
|
|
|
|
|
|
cleanDate(entry);
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::article.article/${entry.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(body.reference.id).toBe(entry.reference);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create article2 with ref1', async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 2',
|
|
|
|
content: 'Content 2',
|
|
|
|
reference: data.references[0].id,
|
|
|
|
};
|
|
|
|
|
|
|
|
let { body } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::article.article',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: entry,
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(body.reference.id).toBe(entry.reference);
|
2020-08-18 17:09:21 +02:00
|
|
|
expect(body.created_by).toMatchObject({ email: 'admin@strapi.io' });
|
|
|
|
expect(body.updated_by).toMatchObject({ email: 'admin@strapi.io' });
|
2019-03-09 01:06:39 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Test oneWay relation (reference - tag) with Content Manager', () => {
|
|
|
|
test('Attach Tag to a Reference', async () => {
|
|
|
|
const { body: tagToCreate } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::tag.tag',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'tag111',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body: referenceToCreate } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::reference.reference',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'cat111',
|
|
|
|
tag: tagToCreate,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Detach Tag to a Reference', async () => {
|
|
|
|
const { body: tagToCreate } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::tag.tag',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'tag111',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body: referenceToCreate } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::reference.reference',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'cat111',
|
|
|
|
tag: tagToCreate,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
|
|
|
|
|
|
|
|
const { body: referenceToUpdate } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::reference.reference/${referenceToCreate.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'PUT',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
tag: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(referenceToUpdate.tag).toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Delete Tag so the relation in the Reference side should be removed', async () => {
|
|
|
|
const { body: tagToCreate } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::tag.tag',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'tag111',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body: referenceToCreate } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: '/content-manager/explorer/application::reference.reference',
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'POST',
|
2019-07-30 16:37:15 +02:00
|
|
|
body: {
|
2019-03-09 01:06:39 +01:00
|
|
|
name: 'cat111',
|
|
|
|
tag: tagToCreate,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::tag.tag/${tagToCreate.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'DELETE',
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body: referenceToGet } = await rq({
|
2020-01-08 13:25:44 +01:00
|
|
|
url: `/content-manager/explorer/application::reference.reference/${referenceToCreate.id}`,
|
2019-03-09 01:06:39 +01:00
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
2020-03-02 15:18:08 +01:00
|
|
|
if (!referenceToGet.tag || Object.keys(referenceToGet.tag).length == 0) return;
|
2019-03-09 01:06:39 +01:00
|
|
|
expect(referenceToGet.tag).toBe(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|