Skip to content

Commit

Permalink
test: add failing test (PUT and PATCH) when a TD id is updated to an …
Browse files Browse the repository at this point in the history
…already existing id
  • Loading branch information
ivanzy committed Sep 6, 2022
1 parent 55f7688 commit 2dc14bb
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion test/e2e/things.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,31 @@ describe('/things', () => {
});
});

it('should fail to update the Thing Description id if the id is already exist', async () => {
const thingDescriptions = [];
const id = `${validThingDescription.id}:${getShortUnique()}`;
for (let i = 0; i < 2; i++) {
const validThingDescriptionObject = validThingDescription;
validThingDescriptionObject.id = `${id}:${i}`;
thingDescriptions.push(validThingDescriptionObject);
const response = await axios.put(`/things/${validThingDescriptionObject.id}`, validThingDescriptionObject, {
headers: { Authorization: `Bearer ${defaultAccessToken}` },
});
expect(response.status).toBe(201);
}
const { status, data } = await axios.put(`/things/${id}:0`, thingDescriptions[1], {
headers: { Authorization: `Bearer ${defaultAccessToken}` },
});

expect(status).toBe(409);
expect(data).toMatchObject({
type: '/errors/types/duplicate-id',
title: 'Duplicate Id',
status: 409,
detail: `The id ${validThingDescription.id} is already in use by another Thing Description`,
});
});

it('should update the Thing Description', async () => {
const { headers } = await axios.post('/things', validAnonymousThingDescription, {
headers: { Authorization: `Bearer ${defaultAccessToken}` },
Expand Down Expand Up @@ -292,7 +317,6 @@ describe('/things', () => {
const id = `${validThingDescription.id}:${getShortUnique()}`;
const validThingDescriptionObject = validThingDescription;
validThingDescriptionObject.id = id;
console.log(validThingDescriptionObject.id);
const { status } = await axios.put(`/things/${id}`, validThingDescriptionObject, {
headers: { Authorization: `Bearer ${defaultAccessToken}` },
});
Expand Down Expand Up @@ -341,6 +365,31 @@ describe('/things', () => {
});
});

it('should fail to update the Thing Description id if the id is already exist', async () => {
const thingDescriptions = [];
const id = `${validThingDescription.id}:${getShortUnique()}`;
for (let i = 0; i < 2; i++) {
const validThingDescriptionObject = validThingDescription;
validThingDescriptionObject.id = `${id}:${i}`;
thingDescriptions.push(validThingDescriptionObject);
const response = await axios.put(`/things/${validThingDescriptionObject.id}`, validThingDescriptionObject, {
headers: { Authorization: `Bearer ${defaultAccessToken}` },
});
expect(response.status).toBe(201);
}
const { status, data } = await axios.patch(`/things/${id}:0`, thingDescriptions[1], {
headers: { Authorization: `Bearer ${defaultAccessToken}`, 'Content-Type': 'application/merge-patch+json' },
});

expect(status).toBe(409);
expect(data).toMatchObject({
type: '/errors/types/duplicate-id',
title: 'Duplicate Id',
status: 409,
detail: `The id ${validThingDescription.id} is already in use by another Thing Description`,
});
});

it('should fail to update the Thing Description when the patched Thing Description is invalid', async () => {
const { headers } = await axios.post('/things', validAnonymousThingDescription, {
headers: { Authorization: `Bearer ${defaultAccessToken}` },
Expand Down

0 comments on commit 2dc14bb

Please sign in to comment.