93 lines
2.3 KiB
JavaScript
Raw Normal View History

'use strict';
const { registerAndLogin } = require('../../../../test/helpers/auth');
const createModelsUtils = require('../../../../test/helpers/models');
const { createAuthRequest } = require('../../../../test/helpers/request');
let modelsUtils;
let rq;
describe('Test type password', () => {
beforeAll(async () => {
const token = await registerAndLogin();
rq = createAuthRequest(token);
modelsUtils = createModelsUtils({ rq });
2019-12-12 10:15:25 +01:00
await modelsUtils.createContentTypeWithType('withpassword', 'password');
}, 60000);
afterAll(async () => {
2019-12-12 10:15:25 +01:00
await modelsUtils.deleteContentType('withpassword');
}, 60000);
test('Create entry with value input JSON', async () => {
const res = await rq.post(
'/content-manager/collection-types/application::withpassword.withpassword',
{
body: {
field: 'somePassword',
},
}
);
expect(res.statusCode).toBe(200);
expect(res.body.field).toBeUndefined();
});
2019-08-08 10:55:22 +02:00
test.todo('Should be private by default');
2019-08-08 10:47:53 +02:00
test('Create entry with value input Formdata', async () => {
const res = await rq.post(
'/content-manager/collection-types/application::withpassword.withpassword',
{
body: {
field: '1234567',
},
}
);
2019-08-08 10:47:53 +02:00
expect(res.statusCode).toBe(200);
expect(res.body.field).toBeUndefined();
2019-08-08 10:47:53 +02:00
});
test('Reading entry returns correct value', async () => {
const res = await rq.get(
'/content-manager/collection-types/application::withpassword.withpassword'
);
2019-08-08 10:47:53 +02:00
expect(res.statusCode).toBe(200);
expect(Array.isArray(res.body)).toBe(true);
res.body.forEach(element => {
expect(element.field).toBeUndefined();
});
2019-08-08 10:47:53 +02:00
});
2019-08-08 10:47:53 +02:00
test('Updating entry sets the right value and format', async () => {
const res = await rq.post(
'/content-manager/collection-types/application::withpassword.withpassword',
{
body: {
field: 'somePassword',
},
}
);
2019-08-08 10:47:53 +02:00
const updateRes = await rq.put(
`/content-manager/collection-types/application::withpassword.withpassword/${res.body.id}`,
2019-08-08 10:47:53 +02:00
{
body: {
field: 'otherPwd',
},
}
);
expect(updateRes.statusCode).toBe(200);
expect(updateRes.body).toMatchObject({
id: res.body.id,
});
expect(res.body.field).toBeUndefined();
2019-08-08 10:47:53 +02:00
});
});