From bef98ddd985ac40a01f9093e5bea698ece40ba74 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Fri, 17 Feb 2023 16:26:41 -0600 Subject: [PATCH] feat: added integration tests for deleteListItemById.spec.ts --- .../Lists/deleteListItemById.spec.ts | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 integrationTests/Lists/deleteListItemById.spec.ts diff --git a/integrationTests/Lists/deleteListItemById.spec.ts b/integrationTests/Lists/deleteListItemById.spec.ts new file mode 100644 index 0000000..746f62c --- /dev/null +++ b/integrationTests/Lists/deleteListItemById.spec.ts @@ -0,0 +1,104 @@ +import { ListItemRequest, OnspringClient } from '../../src'; +import { expect } from 'chai'; +import { baseURL, apiKey } from '../mochaRootHooks'; + +describe('deleteListItemById', function () { + this.timeout(30000); + this.retries(3); + + it('should delete a list item', async function () { + const client = new OnspringClient(baseURL, apiKey); + + if (process.env.TEST_LIST_ID === undefined) { + expect.fail('TEST_LIST_ID is not defined'); + } + + const request = new ListItemRequest( + parseInt(process.env.TEST_LIST_ID), + null, + `added_list_value_${new Date().getTime()}}`, + 1, + '#000000' + ); + + const addListItemResponse = await client.addOrUpdateListItem(request); + const listItemId = addListItemResponse.data?.id; + + if (listItemId === undefined) { + expect.fail('listItemId is undefined'); + } + + const response = await client.deleteListItemById( + parseInt(process.env.TEST_LIST_ID), + listItemId + ); + + expect(response.statusCode).to.equal(204); + expect(response.isSuccessful).to.be.true; + expect(response.message).to.equal(''); + expect(response.data).to.not.be.null; + }); + + it('should return a 401 error when deleting a list item and the API key is invalid', async function () { + const client = new OnspringClient(baseURL, 'invalid'); + const response = await client.deleteListItemById(1, '1'); + + expect(response.statusCode).to.equal(401); + expect(response.isSuccessful).to.be.false; + expect(response.message).to.be.undefined; + expect(response.data).to.be.null; + }); + + it('should return a 403 error when deleting a list item and the api key does not have access to update the list', async function () { + const client = new OnspringClient(baseURL, apiKey); + + if (process.env.TEST_LIST_ID_NO_ACCESS === undefined) { + expect.fail('TEST_LIST_ID_NO_ACCESS is not defined'); + } + + if (process.env.TEST_LIST_ITEM_ID_NO_ACCESS === undefined) { + expect.fail('TEST_LIST_ITEM_ID_NO_ACCESS is not defined'); + } + + const response = await client.deleteListItemById( + parseInt(process.env.TEST_LIST_ID_NO_ACCESS), + process.env.TEST_LIST_ITEM_ID_NO_ACCESS + ); + + expect(response.statusCode).to.equal(403); + expect(response.isSuccessful).to.be.false; + expect(response.message).to.not.be.null.and.not.be.undefined; + expect(response.data).to.be.null; + }); + + it('should return a 404 error when deleting a list item and its list does not exist', async function () { + const client = new OnspringClient(baseURL, apiKey); + const response = await client.deleteListItemById( + 0, + '3fa85f64-5717-4562-b3fc-2c963f66afa6' + ); + + expect(response.statusCode).to.equal(404); + expect(response.isSuccessful).to.be.false; + expect(response.message).to.not.be.null.and.not.be.undefined; + expect(response.data).to.be.null; + }); + + it('should return a 404 error when deleting a list item that does not exist', async function () { + const client = new OnspringClient(baseURL, apiKey); + + if (process.env.TEST_LIST_ID === undefined) { + expect.fail('TEST_LIST_ID is not defined'); + } + + const response = await client.deleteListItemById( + parseInt(process.env.TEST_LIST_ID), + '3fa85f64-5717-4562-b3fc-2c963f66afa6' + ); + + expect(response.statusCode).to.equal(404); + expect(response.isSuccessful).to.be.false; + expect(response.message).to.not.be.null.and.not.be.undefined; + expect(response.data).to.be.null; + }); +});