2022-03-21 20:04:32 +03:00
|
|
|
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
|
|
|
const {anyObjectId, anyISODateTime, anyErrorId, anyEtag, anyLocationFor} = matchers;
|
2020-06-04 14:42:15 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
const matchLabel = {
|
|
|
|
id: anyObjectId,
|
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime
|
|
|
|
};
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
describe('Labels API', function () {
|
|
|
|
let agent;
|
2020-06-04 14:42:15 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
2022-03-21 20:04:32 +03:00
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
|
|
await fixtureManager.init();
|
|
|
|
await agent.loginAsOwner();
|
2020-06-04 14:42:15 +03:00
|
|
|
});
|
|
|
|
|
2022-03-24 13:55:25 +03:00
|
|
|
it('Can browse with no labels', async function () {
|
|
|
|
await agent
|
|
|
|
.get('labels')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot()
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can add', async function () {
|
2022-03-21 20:04:32 +03:00
|
|
|
await agent
|
|
|
|
.post('labels')
|
|
|
|
.body({labels: [{
|
|
|
|
name: 'test'
|
|
|
|
}]})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
labels: [matchLabel]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyLocationFor('labels')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Errors when adding label with the same name', async function () {
|
|
|
|
await agent
|
|
|
|
.post('labels')
|
|
|
|
.body({labels: [{
|
|
|
|
name: 'test'
|
|
|
|
}]})
|
|
|
|
.expectStatus(422)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
2020-06-04 14:42:15 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
}]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
it('Can browse with member count', async function () {
|
|
|
|
await agent
|
|
|
|
.get('labels/?include=count.members')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
labels: [matchLabel]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
it('Can read by slug and edit', async function () {
|
|
|
|
const {body} = await agent
|
|
|
|
.get('labels/slug/test/')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
labels: [matchLabel]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2020-11-30 17:25:22 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
const id = body.labels[0].id;
|
|
|
|
|
|
|
|
await agent
|
|
|
|
.put(`labels/${id}`)
|
|
|
|
.body({labels: [{name: 'testing'}]})
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
labels: [matchLabel]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2020-06-04 14:42:15 +03:00
|
|
|
});
|
2021-07-09 17:21:17 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
it('Can destroy', async function () {
|
|
|
|
const {body} = await agent
|
|
|
|
.get('labels/slug/test/')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
labels: [matchLabel]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2021-07-09 17:21:17 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
const id = body.labels[0].id;
|
2021-07-09 17:21:17 +03:00
|
|
|
|
2022-03-21 20:04:32 +03:00
|
|
|
await agent
|
|
|
|
.delete(`labels/${id}`)
|
|
|
|
.expectStatus(204)
|
2022-03-31 20:55:46 +03:00
|
|
|
.expectEmptyBody()
|
2022-03-21 20:04:32 +03:00
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2021-07-09 17:21:17 +03:00
|
|
|
});
|
2020-06-04 14:42:15 +03:00
|
|
|
});
|