strapi/test/helpers/models.js

89 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-05-06 15:33:25 +02:00
const waitRestart = require('./waitRestart');
module.exports = ({ rq }) => {
2019-10-22 18:01:03 +02:00
async function createComponent(data) {
await rq({
2019-10-22 18:01:03 +02:00
url: '/content-type-builder/components',
method: 'POST',
body: {
2019-11-14 16:37:57 +01:00
component: {
category: 'default',
icon: 'default',
connection: 'default',
...data,
},
},
});
await waitRestart();
}
2019-10-22 18:01:03 +02:00
async function deleteComponent(name) {
await rq({
2019-10-22 18:01:03 +02:00
url: `/content-type-builder/components/${name}`,
method: 'DELETE',
});
await waitRestart();
}
2019-12-12 10:15:25 +01:00
function createContentTypeWithType(name, type, opts = {}) {
return createContentType({
connection: 'default',
name,
2019-11-14 16:37:57 +01:00
attributes: {
field: {
type,
...opts,
},
2019-11-14 16:37:57 +01:00
},
});
}
2019-12-12 10:15:25 +01:00
async function createContentType(data) {
2019-05-06 15:33:25 +02:00
await rq({
2019-11-14 16:37:57 +01:00
url: '/content-type-builder/content-types',
2019-05-06 15:33:25 +02:00
method: 'POST',
body: {
2019-11-14 16:37:57 +01:00
contentType: {
connection: 'default',
...data,
},
},
2019-05-06 15:33:25 +02:00
});
await waitRestart();
}
2019-12-12 10:15:25 +01:00
async function createContentTypes(models) {
2019-05-06 15:33:25 +02:00
for (let model of models) {
2019-12-12 10:15:25 +01:00
await createContentType(model);
2019-05-06 15:33:25 +02:00
}
}
2019-12-12 10:15:25 +01:00
async function deleteContentType(model) {
2019-05-06 15:33:25 +02:00
await rq({
2019-11-14 16:37:57 +01:00
url: `/content-type-builder/content-types/application::${model}.${model}`,
2019-05-06 15:33:25 +02:00
method: 'DELETE',
});
await waitRestart();
}
2019-12-12 10:15:25 +01:00
async function deleteContentTypes(models) {
2019-05-06 15:33:25 +02:00
for (let model of models) {
2019-12-12 10:15:25 +01:00
await deleteContentType(model);
2019-05-06 15:33:25 +02:00
}
}
return {
2019-10-22 18:01:03 +02:00
createComponent,
deleteComponent,
2019-12-12 10:15:25 +01:00
createContentType,
createContentTypes,
createContentTypeWithType,
deleteContentType,
deleteContentTypes,
2019-05-06 15:33:25 +02:00
};
};