2018-05-24 15:12:15 +02:00
|
|
|
let request = require('request');
|
2018-05-18 14:22:24 +02:00
|
|
|
|
2018-06-04 14:39:26 +02:00
|
|
|
const form = require('./helpers/generators');
|
|
|
|
const restart = require('./helpers/restart');
|
2018-05-24 15:12:15 +02:00
|
|
|
|
|
|
|
request = request.defaults({
|
|
|
|
baseUrl: 'http://localhost:1337'
|
2018-05-21 17:04:25 +02:00
|
|
|
});
|
2018-05-18 14:22:24 +02:00
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
const rq = (options) => {
|
|
|
|
const params = JSON.parse(JSON.stringify(options));
|
|
|
|
|
|
|
|
for (let key in params.formData) {
|
|
|
|
if (typeof params.formData[key] === 'object') {
|
|
|
|
params.formData[key] = JSON.stringify(params.formData[key]);
|
|
|
|
}
|
|
|
|
}
|
2018-05-24 15:12:15 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request(params, (err, res, body) => {
|
|
|
|
if (err || res.statusCode < 200 || res.statusCode >= 300) {
|
|
|
|
return reject(err || body);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(body);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-01 14:31:30 +02:00
|
|
|
const cleanDate = (entry) => {
|
|
|
|
delete entry.updatedAt;
|
|
|
|
delete entry.createdAt;
|
|
|
|
delete entry.created_at;
|
|
|
|
delete entry.updated_at;
|
|
|
|
};
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
let data;
|
2018-05-18 14:22:24 +02:00
|
|
|
|
2018-05-21 17:04:25 +02:00
|
|
|
describe('App setup auth', () => {
|
|
|
|
test(
|
|
|
|
'Register admin user',
|
|
|
|
async () => {
|
2018-05-24 15:12:15 +02:00
|
|
|
const body = await rq({
|
|
|
|
url: `/auth/local/register`,
|
|
|
|
method: 'POST',
|
|
|
|
body: {
|
|
|
|
username: 'admin',
|
|
|
|
email: 'admin@strapi.io',
|
|
|
|
password: 'pcw123'
|
|
|
|
},
|
|
|
|
json: true
|
2018-05-18 14:22:24 +02:00
|
|
|
});
|
|
|
|
|
2018-05-24 15:12:15 +02:00
|
|
|
request = request.defaults({
|
|
|
|
headers: {
|
|
|
|
'Authorization': `Bearer ${body.jwt}`
|
|
|
|
}
|
|
|
|
});
|
2018-05-21 17:04:25 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-05-18 14:22:24 +02:00
|
|
|
|
2018-05-21 17:04:25 +02:00
|
|
|
describe('Generate test APIs', () => {
|
|
|
|
beforeEach(async () => {
|
2018-05-24 15:12:15 +02:00
|
|
|
await restart(rq);
|
2018-05-21 17:04:25 +02:00
|
|
|
}, 60000);
|
2018-05-18 14:22:24 +02:00
|
|
|
|
2018-05-21 17:04:25 +02:00
|
|
|
test(
|
|
|
|
'Create new article API',
|
|
|
|
async () => {
|
2018-05-24 15:12:15 +02:00
|
|
|
await rq({
|
|
|
|
url: `/content-type-builder/models`,
|
|
|
|
method: 'POST',
|
|
|
|
body: form.article,
|
|
|
|
json: true
|
|
|
|
});
|
2018-05-21 17:04:25 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create new tag API',
|
|
|
|
async () => {
|
2018-05-24 15:12:15 +02:00
|
|
|
await rq({
|
|
|
|
url: `/content-type-builder/models`,
|
|
|
|
method: 'POST',
|
|
|
|
body: form.tag,
|
|
|
|
json: true
|
|
|
|
});
|
2018-05-21 17:04:25 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create new category API',
|
|
|
|
async () => {
|
2018-05-24 15:12:15 +02:00
|
|
|
await rq({
|
|
|
|
url: `/content-type-builder/models`,
|
|
|
|
method: 'POST',
|
|
|
|
body: form.category,
|
|
|
|
json: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2018-05-29 18:22:02 +02:00
|
|
|
test(
|
|
|
|
'Create new reference API',
|
|
|
|
async () => {
|
|
|
|
await rq({
|
|
|
|
url: `/content-type-builder/models`,
|
|
|
|
method: 'POST',
|
|
|
|
body: form.reference,
|
|
|
|
json: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2018-05-24 15:12:15 +02:00
|
|
|
});
|
|
|
|
|
2018-05-29 10:25:17 +02:00
|
|
|
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
|
2018-05-29 16:30:29 +02:00
|
|
|
beforeAll(() => {
|
|
|
|
data = {
|
|
|
|
articles: [],
|
|
|
|
tags: []
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-05-24 15:12:15 +02:00
|
|
|
beforeEach(async () => {
|
|
|
|
await restart(rq);
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test(
|
2018-05-29 10:25:17 +02:00
|
|
|
'Create tag1',
|
2018-05-24 15:12:15 +02:00
|
|
|
async () => {
|
2018-05-25 16:36:50 +02:00
|
|
|
let body = await rq({
|
2018-05-24 15:12:15 +02:00
|
|
|
url: `/content-manager/explorer/tag/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: {
|
2018-05-29 10:25:17 +02:00
|
|
|
name: 'tag1'
|
2018-05-24 15:12:15 +02:00
|
|
|
}
|
|
|
|
});
|
2018-05-25 16:36:50 +02:00
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.tags.push(body);
|
|
|
|
|
2018-05-25 16:36:50 +02:00
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
2018-05-29 10:25:17 +02:00
|
|
|
expect(body.name).toBe('tag1');
|
2018-05-24 15:12:15 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
2018-05-29 10:25:17 +02:00
|
|
|
'Create tag2',
|
2018-05-24 15:12:15 +02:00
|
|
|
async () => {
|
2018-05-25 16:36:50 +02:00
|
|
|
let body = await rq({
|
2018-05-24 15:12:15 +02:00
|
|
|
url: `/content-manager/explorer/tag/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: {
|
2018-05-29 10:25:17 +02:00
|
|
|
name: 'tag2'
|
2018-05-24 15:12:15 +02:00
|
|
|
}
|
|
|
|
});
|
2018-05-25 16:36:50 +02:00
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.tags.push(body);
|
|
|
|
|
2018-05-25 16:36:50 +02:00
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
2018-05-29 10:25:17 +02:00
|
|
|
expect(body.name).toBe('tag2');
|
2018-05-24 15:12:15 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
2018-05-29 10:25:17 +02:00
|
|
|
'Create tag3',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/tag/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: {
|
|
|
|
name: 'tag3'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.tags.push(body);
|
|
|
|
|
2018-05-29 10:25:17 +02:00
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('tag3');
|
|
|
|
}
|
|
|
|
);
|
2018-05-24 15:12:15 +02:00
|
|
|
test(
|
2018-05-29 10:25:17 +02:00
|
|
|
'Create article1 without relation',
|
2018-05-24 15:12:15 +02:00
|
|
|
async () => {
|
2018-05-25 16:36:50 +02:00
|
|
|
const entry = {
|
|
|
|
title: 'Article 1',
|
2018-05-29 10:25:17 +02:00
|
|
|
content: 'My super content 1'
|
2018-05-25 16:36:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let body = await rq({
|
2018-05-24 15:12:15 +02:00
|
|
|
url: `/content-manager/explorer/article/?source=content-manager`,
|
|
|
|
method: 'POST',
|
2018-05-25 16:36:50 +02:00
|
|
|
formData: entry
|
2018-05-24 15:12:15 +02:00
|
|
|
});
|
2018-05-25 16:36:50 +02:00
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.articles.push(body);
|
|
|
|
|
2018-05-25 16:36:50 +02:00
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
2018-05-29 10:25:17 +02:00
|
|
|
expect(body.tags.length).toBe(0);
|
2018-05-25 16:36:50 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
2018-05-29 10:25:17 +02:00
|
|
|
'Create article2 with tag1',
|
2018-05-25 16:36:50 +02:00
|
|
|
async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 2',
|
2018-05-29 10:25:17 +02:00
|
|
|
content: 'Content 2',
|
2018-05-29 16:30:29 +02:00
|
|
|
tags: [data.tags[0]]
|
2018-05-25 16:36:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.articles.push(body);
|
|
|
|
|
2018-05-25 16:36:50 +02:00
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
expect(Array.isArray(body.tags)).toBeTruthy();
|
2018-05-29 10:25:17 +02:00
|
|
|
expect(body.tags.length).toBe(1);
|
|
|
|
expect(body.tags[0].id).toBe(data.tags[0].id);
|
2018-05-25 16:36:50 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
2018-05-29 10:25:17 +02:00
|
|
|
'Update article1 add tag2',
|
2018-05-25 16:36:50 +02:00
|
|
|
async () => {
|
2018-05-29 10:25:17 +02:00
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
2018-05-29 16:30:29 +02:00
|
|
|
tags: [data.tags[1]]
|
2018-05-25 16:36:50 +02:00
|
|
|
});
|
|
|
|
|
2018-06-01 14:31:30 +02:00
|
|
|
cleanDate(entry);
|
2018-05-25 16:36:50 +02:00
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.articles[0] = body;
|
|
|
|
|
2018-05-25 16:36:50 +02:00
|
|
|
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);
|
2018-05-21 17:04:25 +02:00
|
|
|
}
|
2018-05-18 14:22:24 +02:00
|
|
|
);
|
2018-05-29 10:25:17 +02: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]);
|
|
|
|
|
2018-06-01 14:31:30 +02:00
|
|
|
cleanDate(entry);
|
2018-05-29 10:25:17 +02:00
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.articles[0] = body;
|
|
|
|
|
2018-05-29 10:25:17 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Update article1 remove one tag',
|
|
|
|
async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0]);
|
|
|
|
entry.tags = entry.tags.slice(1);
|
|
|
|
|
2018-06-01 14:31:30 +02:00
|
|
|
cleanDate(entry);
|
2018-05-29 10:25:17 +02:00
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.articles[0] = body;
|
|
|
|
|
2018-05-29 10:25:17 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Update article1 remove all tag',
|
|
|
|
async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
2018-05-29 16:30:29 +02:00
|
|
|
tags: []
|
2018-05-29 10:25:17 +02:00
|
|
|
});
|
|
|
|
|
2018-06-01 14:31:30 +02:00
|
|
|
cleanDate(entry);
|
2018-05-29 10:25:17 +02:00
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
data.articles[0] = body;
|
|
|
|
|
2018-05-29 10:25:17 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
);
|
2018-05-18 14:22:24 +02:00
|
|
|
});
|
2018-05-25 11:49:46 +02:00
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
data = {
|
|
|
|
articles: [],
|
|
|
|
categories: []
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await restart(rq);
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Create cat1',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/category/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: {
|
|
|
|
name: 'cat1'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
data.categories.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('cat1');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create cat2',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/category/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: {
|
|
|
|
name: 'cat2'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
data.categories.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(Array.isArray(body.articles)).toBeTruthy();
|
|
|
|
expect(body.name).toBe('cat2');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create article1 with cat1',
|
|
|
|
async () => {
|
|
|
|
const entry = {
|
2018-06-01 14:31:30 +02:00
|
|
|
title: 'Article 1',
|
|
|
|
content: 'Content 1',
|
2018-05-29 16:30:29 +02:00
|
|
|
category: data.categories[0]
|
|
|
|
};
|
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Update article1 with cat2',
|
|
|
|
async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
|
|
|
category: data.categories[1]
|
|
|
|
});
|
|
|
|
|
2018-06-03 20:46:43 +02:00
|
|
|
cleanDate(entry);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create article2',
|
|
|
|
async () => {
|
|
|
|
const entry = {
|
2018-06-01 14:31:30 +02:00
|
|
|
title: 'Article 2',
|
|
|
|
content: 'Content 2'
|
2018-05-29 16:30:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Update article2 with cat2',
|
|
|
|
async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[1], {
|
|
|
|
category: data.categories[1]
|
|
|
|
});
|
|
|
|
|
2018-06-03 20:46:43 +02:00
|
|
|
cleanDate(entry);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
2018-05-29 18:22:02 +02:00
|
|
|
'Update cat1 with article1',
|
2018-05-29 16:30:29 +02:00
|
|
|
async () => {
|
|
|
|
const entry = Object.assign({}, data.categories[0]);
|
|
|
|
entry.articles.push(data.articles[0]);
|
|
|
|
|
2018-06-03 20:46:43 +02:00
|
|
|
cleanDate(entry);
|
|
|
|
|
2018-05-29 16:30:29 +02:00
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/category/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create cat3 with article1',
|
|
|
|
async () => {
|
|
|
|
const entry = {
|
|
|
|
name: 'cat3',
|
|
|
|
articles: [data.articles[0]]
|
|
|
|
};
|
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/category/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
);
|
2018-06-03 20:46:43 +02:00
|
|
|
test(
|
|
|
|
'Get article1 with cat3',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${data.articles[0].id}?source=content-manager`,
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.category.id).toBe(data.categories[2].id)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Get article2 with cat2',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${data.articles[1].id}?source=content-manager`,
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.category.id).toBe(data.categories[1].id)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Get cat1 without relations',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/category/${data.categories[0].id}?source=content-manager`,
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.articles.length).toBe(0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Get cat2 with article2',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/category/${data.categories[1].id}?source=content-manager`,
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.articles.length).toBe(1);
|
|
|
|
expect(body.articles[0].id).toBe(data.articles[1].id);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Get cat3 with article1',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/category/${data.categories[2].id}?source=content-manager`,
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.articles.length).toBe(1);
|
|
|
|
expect(body.articles[0].id).toBe(data.articles[0].id);
|
|
|
|
}
|
|
|
|
);
|
2018-05-29 16:30:29 +02:00
|
|
|
});
|
|
|
|
|
2018-05-29 18:22:02 +02:00
|
|
|
describe('Test oneToOne relation (article - reference) with Content Manager', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
data = {
|
|
|
|
articles: [],
|
|
|
|
references: []
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await restart(rq);
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Create ref1',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/reference/?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: {
|
|
|
|
name: 'ref1'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
data.references.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.name).toBe('ref1');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create article1',
|
|
|
|
async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 1',
|
|
|
|
content: 'Content 1'
|
|
|
|
};
|
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Update article1 with ref1',
|
|
|
|
async () => {
|
|
|
|
const entry = Object.assign({}, data.articles[0], {
|
2018-06-03 20:46:43 +02:00
|
|
|
reference: data.references[0].id
|
2018-05-29 18:22:02 +02:00
|
|
|
});
|
|
|
|
|
2018-06-03 20:46:43 +02:00
|
|
|
cleanDate(entry);
|
|
|
|
|
2018-05-29 18:22:02 +02:00
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
|
|
|
|
method: 'PUT',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
data.articles[0] = body;
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
2018-06-03 20:46:43 +02:00
|
|
|
expect(body.reference.id).toBe(entry.reference);
|
2018-05-29 18:22:02 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Create article2 with ref1',
|
|
|
|
async () => {
|
|
|
|
const entry = {
|
|
|
|
title: 'Article 2',
|
|
|
|
content: 'Content 2',
|
2018-06-03 20:46:43 +02:00
|
|
|
reference: data.references[0].id
|
2018-05-29 18:22:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article?source=content-manager`,
|
|
|
|
method: 'POST',
|
|
|
|
formData: entry
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
data.articles.push(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.title).toBe(entry.title);
|
|
|
|
expect(body.content).toBe(entry.content);
|
2018-06-03 20:46:43 +02:00
|
|
|
expect(body.reference.id).toBe(entry.reference);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Get article1 without relations',
|
|
|
|
async () => {
|
|
|
|
let body = await rq({
|
|
|
|
url: `/content-manager/explorer/article/${data.articles[0].id}?source=content-manager`,
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
|
|
|
|
expect(body.id);
|
|
|
|
expect(body.reference).toBe(null);
|
2018-05-29 18:22:02 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-05-25 11:49:46 +02:00
|
|
|
describe('Delete test APIs', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await restart(rq);
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Delete article API',
|
|
|
|
async () => {
|
|
|
|
await rq({
|
|
|
|
url: `/content-type-builder/models/article`,
|
|
|
|
method: 'DELETE',
|
|
|
|
json: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Delete tag API',
|
|
|
|
async () => {
|
|
|
|
await rq({
|
|
|
|
url: `/content-type-builder/models/tag`,
|
|
|
|
method: 'DELETE',
|
|
|
|
json: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
test(
|
|
|
|
'Delete category API',
|
|
|
|
async () => {
|
|
|
|
await rq({
|
|
|
|
url: `/content-type-builder/models/category`,
|
|
|
|
method: 'DELETE',
|
|
|
|
json: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|