2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-02-13 11:35:36 +01:00
|
|
|
const { registerAndLogin } = require('../../../../test/helpers/auth');
|
|
|
|
const createModelsUtils = require('../../../../test/helpers/models');
|
2020-02-13 15:28:54 +01:00
|
|
|
const { createAuthRequest } = require('../../../../test/helpers/request');
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
let modelsUtils;
|
|
|
|
let rq;
|
|
|
|
|
|
|
|
describe('Test type UID', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
const token = await registerAndLogin();
|
|
|
|
rq = createAuthRequest(token);
|
|
|
|
|
|
|
|
modelsUtils = createModelsUtils({ rq });
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('No targetField, required=false, not length limits', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await modelsUtils.createContentType({
|
|
|
|
name: 'withuid',
|
|
|
|
attributes: {
|
|
|
|
slug: {
|
|
|
|
type: 'uid',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await modelsUtils.deleteContentType('withuid');
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test('Creates an entry successfully', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.post('/content-manager/collection-types/application::withuid.withuid', {
|
2020-03-02 15:18:08 +01:00
|
|
|
body: {
|
|
|
|
slug: 'valid-uid',
|
|
|
|
},
|
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'valid-uid',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Throws error on duplicate value', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.post('/content-manager/collection-types/application::withuid.withuid', {
|
2020-03-02 15:18:08 +01:00
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
});
|
|
|
|
|
2020-11-02 12:40:35 +01:00
|
|
|
const conflicting = await rq.post(
|
|
|
|
'/content-manager/collection-types/application::withuid.withuid',
|
|
|
|
{
|
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(conflicting.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Can set value to be null', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.post('/content-manager/collection-types/application::withuid.withuid', {
|
2020-03-02 15:18:08 +01:00
|
|
|
body: {
|
|
|
|
slug: null,
|
|
|
|
},
|
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('No targetField, required, no length limits', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await modelsUtils.createContentType({
|
|
|
|
name: 'withrequireduid',
|
|
|
|
attributes: {
|
|
|
|
slug: {
|
|
|
|
type: 'uid',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await modelsUtils.deleteContentType('withrequireduid');
|
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test('Creates an entry successfully', async () => {
|
|
|
|
const res = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
slug: 'valid-uid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'valid-uid',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Throws error on duplicate value', async () => {
|
|
|
|
const res = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
});
|
|
|
|
|
|
|
|
const conflicting = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(conflicting.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Cannot set value to be null', async () => {
|
|
|
|
const res = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
2020-02-17 15:54:49 +01:00
|
|
|
body: {
|
|
|
|
slug: null,
|
|
|
|
},
|
2020-02-13 11:35:36 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|