strapi/test/index.test.js

143 lines
2.8 KiB
JavaScript
Raw Normal View History

let request = require('request');
2018-05-18 14:22:24 +02:00
const form = require('./helper/generators');
const restart = require('./helper/restart');
request = request.defaults({
baseUrl: 'http://localhost:1337'
});
2018-05-18 14:22:24 +02:00
const rq = (params) => {
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);
});
});
}
const data = {};
2018-05-18 14:22:24 +02:00
describe('App setup auth', () => {
test(
'Register admin user',
async () => {
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
});
request = request.defaults({
headers: {
'Authorization': `Bearer ${body.jwt}`
}
});
}
);
});
2018-05-18 14:22:24 +02:00
describe('Generate test APIs', () => {
beforeEach(async () => {
await restart(rq);
}, 60000);
2018-05-18 14:22:24 +02:00
test(
'Create new article API',
async () => {
await rq({
url: `/content-type-builder/models`,
method: 'POST',
body: form.article,
json: true
});
}
);
test(
'Create new tag API',
async () => {
await rq({
url: `/content-type-builder/models`,
method: 'POST',
body: form.tag,
json: true
});
}
);
test(
'Create new category API',
async () => {
await rq({
url: `/content-type-builder/models`,
method: 'POST',
body: form.category,
json: true
});
}
);
});
describe('Test data GET/POST/PUT/DELETE with Content Manager', () => {
beforeEach(async () => {
await restart(rq);
}, 60000);
test(
'Create tag news',
async () => {
await rq({
url: `/content-manager/explorer/tag/?source=content-manager`,
method: 'POST',
formData: {
name: 'news'
}
});
}
);
test(
'Create tag article',
async () => {
await rq({
url: `/content-manager/explorer/tag/?source=content-manager`,
method: 'POST',
formData: {
name: 'content'
}
});
}
);
test(
'Get tags',
async () => {
const body = await rq({
url: `/tag`,
method: 'GET'
});
data.tags = JSON.parse(body);
}
);
test(
'Create article 1 with tag relation',
async () => {
await rq({
url: `/content-manager/explorer/article/?source=content-manager`,
method: 'POST',
formData: {
title: 'Article 1',
content: 'My super content 1',
tags: JSON.stringify([data.tags[0]])
}
});
}
2018-05-18 14:22:24 +02:00
);
});