101 lines
2.4 KiB
JavaScript
Raw Normal View History

'use strict';
const { createTestBuilder } = require('../../../../test/helpers/builder');
const { createStrapiInstance } = require('../../../../test/helpers/strapi');
const { createAuthRequest } = require('../../../../test/helpers/request');
const builder = createTestBuilder();
let strapi;
let rq;
const ct = {
name: 'withpassword',
attributes: {
field: {
type: 'password',
},
},
};
describe('Test type password', () => {
beforeAll(async () => {
await builder.addContentType(ct).build();
strapi = await createStrapiInstance({ ensureSuperAdmin: true });
rq = await createAuthRequest({ strapi });
}, 60000);
afterAll(async () => {
await strapi.destroy();
await builder.cleanup();
}, 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.results)).toBe(true);
res.body.results.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
});
});