From 2f32a1bb2901eaa5a8090cbc28bc129c63db1490 Mon Sep 17 00:00:00 2001 From: Syndesi Date: Thu, 21 Mar 2024 08:43:36 +0100 Subject: [PATCH 1/3] Fix markdown files. --- docs/_sidebar.md | 3 --- docs/endpoints/element/get-element.md | 10 +++------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/docs/_sidebar.md b/docs/_sidebar.md index f2e6be8..3211618 100755 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -1,12 +1,9 @@ - [Home](/) - - **Browser Events** - **Element Events** - [GetElementEvent](/browser-events/element/get-element) - - - **Endpoints** - **Element Endpoints** - [GET` / -` Get Element](/endpoints/element/get-element) diff --git a/docs/endpoints/element/get-element.md b/docs/endpoints/element/get-element.md index 264ad2c..8be352d 100644 --- a/docs/endpoints/element/get-element.md +++ b/docs/endpoints/element/get-element.md @@ -8,22 +8,19 @@ The get element endpoint is used to retrieve data of a specific element, either > [!NOTE] > This implementation calls the same endpoint in the Ember Nexus API. See their documentation for more details. > -> Ember Nexus API's documentation +> link to external siteEmber Nexus API's documentation > [!WARNING] > This implementation calls the same endpoint in the Ember Nexus API. See their documentation for more details. - > [!SECURITY] > This implementation calls the same endpoint in the Ember Nexus API. See their documentation for more details. - - -It corresponds to the API endpoint GET `/` +It corresponds to the API endpoint GET `/` ## Method -The +The ... ## Browser event @@ -32,4 +29,3 @@ The workflow - From 3e458e4286b8ca2f1e8e2451fac2b86579768a7d Mon Sep 17 00:00:00 2001 From: Syndesi Date: Thu, 21 Mar 2024 08:47:19 +0100 Subject: [PATCH 2/3] Remove old code. --- .../GetElement/getElementBadResponse.ts | 24 ---- .../getElementErrorNetworkResponse.ts | 7 -- .../getElementNoContentTypeResponse.ts | 25 ----- .../GetElement/getElementNormal200Response.ts | 35 ------ .../getElementNotFound404Response.ts | 31 ----- .../getElementTooManyRequests429Response.ts | 31 ----- .../getElementUnauthorized401Response.ts | 32 ------ test/MockServer/mockServer.ts | 22 ---- .../GetElementChildrenEndpoint.test.ts | 89 --------------- .../Element/GetElementEndpoint.test.ts | 106 ------------------ .../Element/GetElementParentsEndpoint.test.ts | 89 --------------- .../Element/GetElementRelatedEndpoint.test.ts | 89 --------------- .../Element/GetIndexEndpoint.test.ts | 63 ----------- .../Element/PostIndexEndpoint.test.ts | 75 ------------- .../User/GetMeEndpoint.test.ts | 65 ----------- .../User/GetTokenEndpoint.test.ts | 65 ----------- 16 files changed, 848 deletions(-) delete mode 100644 test/MockServer/Element/GetElement/getElementBadResponse.ts delete mode 100644 test/MockServer/Element/GetElement/getElementErrorNetworkResponse.ts delete mode 100644 test/MockServer/Element/GetElement/getElementNoContentTypeResponse.ts delete mode 100644 test/MockServer/Element/GetElement/getElementNormal200Response.ts delete mode 100644 test/MockServer/Element/GetElement/getElementNotFound404Response.ts delete mode 100644 test/MockServer/Element/GetElement/getElementTooManyRequests429Response.ts delete mode 100644 test/MockServer/Element/GetElement/getElementUnauthorized401Response.ts delete mode 100644 test/MockServer/mockServer.ts delete mode 100644 test/OldFeatureEndpoint/Element/GetElementChildrenEndpoint.test.ts delete mode 100644 test/OldFeatureEndpoint/Element/GetElementEndpoint.test.ts delete mode 100644 test/OldFeatureEndpoint/Element/GetElementParentsEndpoint.test.ts delete mode 100644 test/OldFeatureEndpoint/Element/GetElementRelatedEndpoint.test.ts delete mode 100644 test/OldFeatureEndpoint/Element/GetIndexEndpoint.test.ts delete mode 100644 test/OldFeatureEndpoint/Element/PostIndexEndpoint.test.ts delete mode 100644 test/OldFeatureEndpoint/User/GetMeEndpoint.test.ts delete mode 100644 test/OldFeatureEndpoint/User/GetTokenEndpoint.test.ts diff --git a/test/MockServer/Element/GetElement/getElementBadResponse.ts b/test/MockServer/Element/GetElement/getElementBadResponse.ts deleted file mode 100644 index 53a8123..0000000 --- a/test/MockServer/Element/GetElement/getElementBadResponse.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { HttpResponse, http } from 'msw'; - -const getElementBadResponse = http.get('http://mock-api/afaa7a87-e523-4bf0-afe8-d2a11802c549', () => { - return HttpResponse.text('Some content which can not be interpreted as JSON.', { - status: 200, - headers: { - 'Access-Control-Allow-Headers': - 'Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method', - 'Access-Control-Allow-Methods': - 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Access-Control-Allow-Origin': '*', - Allow: 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Cache-Control': 'no-cache, private', - 'Content-Type': 'text/plain; charset=utf-8', - Date: 'Fri, 06 Oct 2023 20:24:10 GMT', - Etag: '"YgbFC4u5EgC"', - Server: 'Unit', - 'Transfer-Encoding': 'chunked', - 'X-Powered-By': 'Ember Nexus API', - }, - }); -}); - -export { getElementBadResponse }; diff --git a/test/MockServer/Element/GetElement/getElementErrorNetworkResponse.ts b/test/MockServer/Element/GetElement/getElementErrorNetworkResponse.ts deleted file mode 100644 index cd018f1..0000000 --- a/test/MockServer/Element/GetElement/getElementErrorNetworkResponse.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { http } from 'msw'; - -const getElementErrorNetworkResponse = http.get('http://mock-api/df6604fb-72a1-4616-90b1-e72eee3aca6c', () => { - return Response.error(); -}); - -export { getElementErrorNetworkResponse }; diff --git a/test/MockServer/Element/GetElement/getElementNoContentTypeResponse.ts b/test/MockServer/Element/GetElement/getElementNoContentTypeResponse.ts deleted file mode 100644 index 8d32562..0000000 --- a/test/MockServer/Element/GetElement/getElementNoContentTypeResponse.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { HttpResponse, http } from 'msw'; - -const getElementNoContentTypeResponse = http.get('http://mock-api/d00d3faf-5dc9-43f1-9efc-f78c2d7efa77', () => { - const response = HttpResponse.text('Some content which can not be interpreted as JSON.', { - status: 200, - headers: { - 'Access-Control-Allow-Headers': - 'Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method', - 'Access-Control-Allow-Methods': - 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Access-Control-Allow-Origin': '*', - Allow: 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Cache-Control': 'no-cache, private', - Date: 'Fri, 06 Oct 2023 20:24:10 GMT', - Etag: '"YgbFC4u5EgC"', - Server: 'Unit', - 'Transfer-Encoding': 'chunked', - 'X-Powered-By': 'Ember Nexus API', - }, - }); - response.headers.delete('Content-Type'); - return response; -}); - -export { getElementNoContentTypeResponse }; diff --git a/test/MockServer/Element/GetElement/getElementNormal200Response.ts b/test/MockServer/Element/GetElement/getElementNormal200Response.ts deleted file mode 100644 index a52f27e..0000000 --- a/test/MockServer/Element/GetElement/getElementNormal200Response.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { HttpResponse, http } from 'msw'; - -const getElementNormal200Response = http.get('http://mock-api/b1e85bf9-6a79-4e50-ae5a-ed49beac8cb5', () => { - return HttpResponse.json( - { - type: 'Data', - id: 'b1e85bf9-6a79-4e50-ae5a-ed49beac8cb5', - data: { - created: '2023-10-06T20:27:56+00:00', - updated: '2023-10-06T20:27:56+00:00', - name: 'Test Data', - }, - }, - { - status: 200, - headers: { - 'Access-Control-Allow-Headers': - 'Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method', - 'Access-Control-Allow-Methods': - 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Access-Control-Allow-Origin': '*', - Allow: 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Cache-Control': 'no-cache, private', - 'Content-Type': 'application/json; charset=utf-8', - Date: 'Fri, 06 Oct 2023 20:24:10 GMT', - Etag: '"YgbFC4u5EgC"', - Server: 'Unit', - 'Transfer-Encoding': 'chunked', - 'X-Powered-By': 'Ember Nexus API', - }, - }, - ); -}); - -export { getElementNormal200Response }; diff --git a/test/MockServer/Element/GetElement/getElementNotFound404Response.ts b/test/MockServer/Element/GetElement/getElementNotFound404Response.ts deleted file mode 100644 index c1ef553..0000000 --- a/test/MockServer/Element/GetElement/getElementNotFound404Response.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { HttpResponse, http } from 'msw'; - -const getElementNotFound404Response = http.get('http://mock-api/2fe89dfb-ef1c-4964-99da-73161077e951', () => { - return HttpResponse.json( - { - type: 'http://ember-nexus-api/error/404/not-found', - title: 'NotFound', - status: 404, - detail: 'Requested element was not found.', - }, - { - status: 404, - headers: { - 'Access-Control-Allow-Headers': - 'Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method', - 'Access-Control-Allow-Methods': - 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Access-Control-Allow-Origin': '*', - Allow: 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Cache-Control': 'no-cache, private', - 'Content-Type': 'application/problem+json; charset=utf-8', - Date: 'Fri, 06 Oct 2023 20:24:10 GMT', - Server: 'Unit', - 'Transfer-Encoding': 'chunked', - 'X-Powered-By': 'Ember Nexus API', - }, - }, - ); -}); - -export { getElementNotFound404Response }; diff --git a/test/MockServer/Element/GetElement/getElementTooManyRequests429Response.ts b/test/MockServer/Element/GetElement/getElementTooManyRequests429Response.ts deleted file mode 100644 index 9c3c45f..0000000 --- a/test/MockServer/Element/GetElement/getElementTooManyRequests429Response.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { HttpResponse, http } from 'msw'; - -const getElementTooManyRequests429Response = http.get('http://mock-api/43d39932-2882-43c2-b526-1ab282bc145d', () => { - return HttpResponse.json( - { - type: 'http://ember-nexus-api/error/429/too-many-requests', - title: 'Unauthorized', - status: 429, - detail: 'wip', - }, - { - status: 429, - headers: { - 'Access-Control-Allow-Headers': - 'Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method', - 'Access-Control-Allow-Methods': - 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Access-Control-Allow-Origin': '*', - Allow: 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Cache-Control': 'no-cache, private', - 'Content-Type': 'application/problem+json; charset=utf-8', - Date: 'Fri, 06 Oct 2023 20:24:10 GMT', - Server: 'Unit', - 'Transfer-Encoding': 'chunked', - 'X-Powered-By': 'Ember Nexus API', - }, - }, - ); -}); - -export { getElementTooManyRequests429Response }; diff --git a/test/MockServer/Element/GetElement/getElementUnauthorized401Response.ts b/test/MockServer/Element/GetElement/getElementUnauthorized401Response.ts deleted file mode 100644 index fe8db62..0000000 --- a/test/MockServer/Element/GetElement/getElementUnauthorized401Response.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { HttpResponse, http } from 'msw'; - -const getElementUnauthorized401Response = http.get('http://mock-api/5324396a-636a-4263-ac38-62fef3132ead', () => { - return HttpResponse.json( - { - type: 'http://ember-nexus-api/error/401/unauthorized', - title: 'Unauthorized', - status: 401, - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - }, - { - status: 401, - headers: { - 'Access-Control-Allow-Headers': - 'Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method', - 'Access-Control-Allow-Methods': - 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Access-Control-Allow-Origin': '*', - Allow: 'GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK', - 'Cache-Control': 'no-cache, private', - 'Content-Type': 'application/problem+json; charset=utf-8', - Date: 'Fri, 06 Oct 2023 20:24:10 GMT', - Server: 'Unit', - 'Transfer-Encoding': 'chunked', - 'X-Powered-By': 'Ember Nexus API', - }, - }, - ); -}); - -export { getElementUnauthorized401Response }; diff --git a/test/MockServer/mockServer.ts b/test/MockServer/mockServer.ts deleted file mode 100644 index ff817ce..0000000 --- a/test/MockServer/mockServer.ts +++ /dev/null @@ -1,22 +0,0 @@ -// eslint-disable-next-line import/no-unresolved -import { setupServer } from 'msw/node'; - -import { getElementBadResponse } from './Element/GetElement/getElementBadResponse'; -import { getElementErrorNetworkResponse } from './Element/GetElement/getElementErrorNetworkResponse'; -import { getElementNoContentTypeResponse } from './Element/GetElement/getElementNoContentTypeResponse'; -import { getElementNormal200Response } from './Element/GetElement/getElementNormal200Response'; -import { getElementNotFound404Response } from './Element/GetElement/getElementNotFound404Response'; -import { getElementTooManyRequests429Response } from './Element/GetElement/getElementTooManyRequests429Response'; -import { getElementUnauthorized401Response } from './Element/GetElement/getElementUnauthorized401Response'; - -const mockServer = setupServer( - getElementNormal200Response, - getElementErrorNetworkResponse, - getElementBadResponse, - getElementNoContentTypeResponse, - getElementUnauthorized401Response, - getElementNotFound404Response, - getElementTooManyRequests429Response, -); - -export { mockServer }; diff --git a/test/OldFeatureEndpoint/Element/GetElementChildrenEndpoint.test.ts b/test/OldFeatureEndpoint/Element/GetElementChildrenEndpoint.test.ts deleted file mode 100644 index a7482dd..0000000 --- a/test/OldFeatureEndpoint/Element/GetElementChildrenEndpoint.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, assert, createSandbox, match } from 'sinon'; -import { Container } from 'typedi'; - -import GetElementChildrenEndpoint from '~/Endpoint/Element/GetElementChildrenEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { Token, validateTokenFromString } from '~/Type/Definition/Token'; -import { validateUuidFromString } from '~/Type/Definition/Uuid'; - -describe('GetElementChildrenEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - const _token: Token = validateTokenFromString('secret-token:PIPeJGUt7c00ENn8a5uDlc'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - it('should load children of a node', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const parentUuid = validateUuidFromString('56fda20c-b238-4034-b555-1df47c47e17a'); - const collection = await Container.get(GetElementChildrenEndpoint).getElementChildren(parentUuid); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/56fda20c-b238-4034-b555-1df47c47e17a/children?page=1&pageSize=25 .', - ); - - expect(collection).to.have.keys('id', 'totalNodes', 'links', 'nodes', 'relations'); - expect(collection.nodes).to.have.lengthOf(6); - expect(collection.relations).to.have.lengthOf(6); - }); - - it('should throw error 401 if token is invalid', async () => { - Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - const parentUuid = validateUuidFromString('56fda20c-b238-4034-b555-1df47c47e17a'); - - await expect( - Container.get(GetElementChildrenEndpoint).getElementChildren(parentUuid), - ).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Unauthorized', - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - status: 401, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/56fda20c-b238-4034-b555-1df47c47e17a/children?page=1&pageSize=25 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); - - it('should throw error 404 if element is not found', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - const uuidWhichDoesNotExist = validateUuidFromString('00000000-0000-4000-a000-000000000000'); - - await expect( - Container.get(GetElementChildrenEndpoint).getElementChildren(uuidWhichDoesNotExist), - ).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Not found', - detail: 'Requested element was not found.', - status: 404, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/00000000-0000-4000-a000-000000000000/children?page=1&pageSize=25 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); -}); diff --git a/test/OldFeatureEndpoint/Element/GetElementEndpoint.test.ts b/test/OldFeatureEndpoint/Element/GetElementEndpoint.test.ts deleted file mode 100644 index d20a432..0000000 --- a/test/OldFeatureEndpoint/Element/GetElementEndpoint.test.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, assert, createSandbox, match } from 'sinon'; -import { Container } from 'typedi'; - -import GetElementEndpoint from '~/Endpoint/Element/GetElementEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { Token, validateTokenFromString } from '~/Type/Definition/Token'; -import { validateUuidFromString } from '~/Type/Definition/Uuid'; - -describe('GetElementEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - const _token: Token = validateTokenFromString('secret-token:Au6srY6s3cW5THS6LeCl9Z'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - it('should load an accessible node', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const nodeUuid = validateUuidFromString('b1e85bf9-6a79-4e50-ae5a-ed49beac8cb5'); - const node = await Container.get(GetElementEndpoint).getElement(nodeUuid); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/b1e85bf9-6a79-4e50-ae5a-ed49beac8cb5 .', - ); - - expect(node).to.have.keys('id', 'type', 'data'); - expect(node).to.not.have.keys('start', 'end'); - expect(node.id).to.equal(nodeUuid); - expect(node.type).to.equal('Data'); - expect(Object.keys(node.data)).to.have.lengthOf(4); - }); - - it('should load an accessible relation', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const relationUuid = validateUuidFromString('fd9f4b9b-9831-4d8a-be98-a438f28e5038'); - const relation = await Container.get(GetElementEndpoint).getElement(relationUuid); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/fd9f4b9b-9831-4d8a-be98-a438f28e5038 .', - ); - - expect(relation).to.have.keys('id', 'type', 'data', 'start', 'end'); - expect(relation.id).to.equal(relationUuid); - expect(relation.type).to.equal('RELATION'); - expect(Object.keys(relation.data)).to.have.lengthOf(3); - }); - - it('should throw error 401 if token is invalid', async () => { - Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - const nodeUuid = validateUuidFromString('b1e85bf9-6a79-4e50-ae5a-ed49beac8cb5'); - - await expect(Container.get(GetElementEndpoint).getElement(nodeUuid)).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Unauthorized', - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - status: 401, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/b1e85bf9-6a79-4e50-ae5a-ed49beac8cb5 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); - - it('should throw error 404 if element is not found', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - const uuidWhichDoesNotExist = validateUuidFromString('00000000-0000-4000-a000-000000000000'); - - await expect( - Container.get(GetElementEndpoint).getElement(uuidWhichDoesNotExist), - ).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Not found', - detail: 'Requested element was not found.', - status: 404, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/00000000-0000-4000-a000-000000000000 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); -}); diff --git a/test/OldFeatureEndpoint/Element/GetElementParentsEndpoint.test.ts b/test/OldFeatureEndpoint/Element/GetElementParentsEndpoint.test.ts deleted file mode 100644 index 659ecac..0000000 --- a/test/OldFeatureEndpoint/Element/GetElementParentsEndpoint.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, assert, createSandbox, match } from 'sinon'; -import { Container } from 'typedi'; - -import GetElementParentsEndpoint from '~/Endpoint/Element/GetElementParentsEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { Token, validateTokenFromString } from '~/Type/Definition/Token'; -import { validateUuidFromString } from '~/Type/Definition/Uuid'; - -describe('GetElementParentsEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - const _token: Token = validateTokenFromString('secret-token:PIPeJGUt7c00ENn8a5uDlc'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - it('should load parents of a node', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const childUuid = validateUuidFromString('45482998-274a-43d0-a466-f31d0b24cc0a'); - const collection = await Container.get(GetElementParentsEndpoint).getElementParents(childUuid); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/45482998-274a-43d0-a466-f31d0b24cc0a/parents?page=1&pageSize=25 .', - ); - - expect(collection).to.have.keys('id', 'totalNodes', 'links', 'nodes', 'relations'); - expect(collection.nodes).to.have.lengthOf(1); - expect(collection.relations).to.have.lengthOf(1); - }); - - it('should throw error 401 if token is invalid', async () => { - Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - const childUuid = validateUuidFromString('45482998-274a-43d0-a466-f31d0b24cc0a'); - - await expect( - Container.get(GetElementParentsEndpoint).getElementParents(childUuid), - ).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Unauthorized', - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - status: 401, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/45482998-274a-43d0-a466-f31d0b24cc0a/parents?page=1&pageSize=25 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); - - it('should throw error 404 if element is not found', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - const uuidWhichDoesNotExist = validateUuidFromString('00000000-0000-4000-a000-000000000000'); - - await expect( - Container.get(GetElementParentsEndpoint).getElementParents(uuidWhichDoesNotExist), - ).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Not found', - detail: 'Requested element was not found.', - status: 404, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/00000000-0000-4000-a000-000000000000/parents?page=1&pageSize=25 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); -}); diff --git a/test/OldFeatureEndpoint/Element/GetElementRelatedEndpoint.test.ts b/test/OldFeatureEndpoint/Element/GetElementRelatedEndpoint.test.ts deleted file mode 100644 index df467ff..0000000 --- a/test/OldFeatureEndpoint/Element/GetElementRelatedEndpoint.test.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, assert, createSandbox, match } from 'sinon'; -import { Container } from 'typedi'; - -import GetElementRelatedEndpoint from '~/Endpoint/Element/GetElementRelatedEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { Token, validateTokenFromString } from '~/Type/Definition/Token'; -import { validateUuidFromString } from '~/Type/Definition/Uuid'; - -describe('GetElementRelatedEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - const _token: Token = validateTokenFromString('secret-token:PIPeJGUt7c00ENn8a5uDlc'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - it('should load related elements of a node', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const centerUuid = validateUuidFromString('45482998-274a-43d0-a466-f31d0b24cc0a'); - const collection = await Container.get(GetElementRelatedEndpoint).getElementRelated(centerUuid); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/45482998-274a-43d0-a466-f31d0b24cc0a/related?page=1&pageSize=25 .', - ); - - expect(collection).to.have.keys('id', 'totalNodes', 'links', 'nodes', 'relations'); - expect(collection.nodes).to.have.lengthOf(3); - expect(collection.relations).to.have.lengthOf(3); - }); - - it('should throw error 401 if token is invalid', async () => { - Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - const centerUuid = validateUuidFromString('45482998-274a-43d0-a466-f31d0b24cc0a'); - - await expect( - Container.get(GetElementRelatedEndpoint).getElementRelated(centerUuid), - ).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Unauthorized', - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - status: 401, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/45482998-274a-43d0-a466-f31d0b24cc0a/related?page=1&pageSize=25 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); - - it('should throw error 404 if element is not found', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - const uuidWhichDoesNotExist = validateUuidFromString('00000000-0000-4000-a000-000000000000'); - - await expect( - Container.get(GetElementRelatedEndpoint).getElementRelated(uuidWhichDoesNotExist), - ).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Not found', - detail: 'Requested element was not found.', - status: 404, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/00000000-0000-4000-a000-000000000000/related?page=1&pageSize=25 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); -}); diff --git a/test/OldFeatureEndpoint/Element/GetIndexEndpoint.test.ts b/test/OldFeatureEndpoint/Element/GetIndexEndpoint.test.ts deleted file mode 100644 index d791d95..0000000 --- a/test/OldFeatureEndpoint/Element/GetIndexEndpoint.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, assert, createSandbox, match } from 'sinon'; -import { Container } from 'typedi'; - -import GetIndexEndpoint from '~/Endpoint/Element/GetIndexEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { Token, validateTokenFromString } from '~/Type/Definition/Token'; - -describe('GetIndexEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - const _token: Token = validateTokenFromString('secret-token:PIPeJGUt7c00ENn8a5uDlc'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - it('should load index', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const collection = await Container.get(GetIndexEndpoint).getIndex(); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/?page=1&pageSize=25 .', - ); - - expect(collection).to.have.keys('id', 'totalNodes', 'links', 'nodes', 'relations'); - expect(collection.nodes).to.have.lengthOf(3); - expect(collection.relations).to.have.lengthOf(0); - }); - - it('should throw error 401 if token is invalid', async () => { - Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - - await expect(Container.get(GetIndexEndpoint).getIndex()).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Unauthorized', - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - status: 401, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/?page=1&pageSize=25 .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); -}); diff --git a/test/OldFeatureEndpoint/Element/PostIndexEndpoint.test.ts b/test/OldFeatureEndpoint/Element/PostIndexEndpoint.test.ts deleted file mode 100644 index e37a7e3..0000000 --- a/test/OldFeatureEndpoint/Element/PostIndexEndpoint.test.ts +++ /dev/null @@ -1,75 +0,0 @@ -// import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, createSandbox } from 'sinon'; -import { Container } from 'typedi'; - -// import PostIndexEndpoint from '~/Endpoint/Element/PostIndexEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -// import { NodeWithOptionalId } from '~/Type/Definition/NodeWithOptionalId'; -// import { Token, validateTokenFromString } from '~/Type/Definition/Token'; - -describe('PostIndexEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - // const _token: Token = validateTokenFromString('secret-token:PIPeJGUt7c00ENn8a5uDlc'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - // it('should post node without id to index', async () => { - // Container.get(WebSdkConfiguration).setToken(_token); - // - // const node: NodeWithOptionalId = { - // type: 'Data', - // data: { - // hello: 'world', - // date: new Date(), - // tag: 'DateTag' - // }, - // }; - // - // const location = await Container.get(PostIndexEndpoint).postIndex(node); - // - // assert.calledOnceWithExactly( - // mockedLogger.debug, - // 'Executing HTTP POST request against url http://ember-nexus-dev-api/ .', - // ); - // - // console.log(location); - // - // // expect(collection).to.have.keys('id', 'totalNodes', 'links', 'nodes', 'relations'); - // // expect(collection.nodes).to.have.lengthOf(3); - // // expect(collection.relations).to.have.lengthOf(0); - // }); - - // it('should throw error 401 if token is invalid', async () => { - // Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - // - // await expect(Container.get(PostIndexEndpoint).getIndex()).to.eventually.be.rejected.and.deep.include({ - // category: 'server', - // title: 'Unauthorized', - // detail: - // "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - // status: 401, - // }); - // - // assert.calledOnceWithExactly( - // mockedLogger.debug, - // 'Executing HTTP GET request against url http://ember-nexus-dev-api/?page=1&pageSize=25 .', - // ); - // - // assert.calledOnceWithExactly(mockedLogger.error, match.object); - // }); -}); diff --git a/test/OldFeatureEndpoint/User/GetMeEndpoint.test.ts b/test/OldFeatureEndpoint/User/GetMeEndpoint.test.ts deleted file mode 100644 index 9e99ba6..0000000 --- a/test/OldFeatureEndpoint/User/GetMeEndpoint.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, assert, createSandbox, match } from 'sinon'; -import { Container } from 'typedi'; - -import GetMeEndpoint from '~/Endpoint/User/GetMeEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { Token, validateTokenFromString } from '~/Type/Definition/Token'; - -describe('GetMeEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - const _token: Token = validateTokenFromString('secret-token:PIPeJGUt7c00ENn8a5uDlc'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - it('should load me', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const me = await Container.get(GetMeEndpoint).getMe(); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/me .', - ); - - expect(me).to.have.keys('id', 'type', 'data'); - expect(me).to.not.have.keys('start', 'end'); - expect(me.id).to.equal('7e86b9ec-b1dc-4aed-a627-eb77b265e12c'); - expect(me.type).to.equal('User'); - expect(Object.keys(me.data)).to.have.lengthOf(4); - }); - - it('should throw error 401 if token is invalid', async () => { - Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - - await expect(Container.get(GetMeEndpoint).getMe()).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Unauthorized', - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - status: 401, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/me .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); -}); diff --git a/test/OldFeatureEndpoint/User/GetTokenEndpoint.test.ts b/test/OldFeatureEndpoint/User/GetTokenEndpoint.test.ts deleted file mode 100644 index 0662ac3..0000000 --- a/test/OldFeatureEndpoint/User/GetTokenEndpoint.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { expect } from 'chai'; -import { SinonSandbox, SinonStubbedInstance, assert, createSandbox, match } from 'sinon'; -import { Container } from 'typedi'; - -import GetTokenEndpoint from '~/Endpoint/User/GetTokenEndpoint'; -import { Logger } from '~/Service/Logger'; -import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { Token, validateTokenFromString } from '~/Type/Definition/Token'; - -describe('GetTokenEndpoint tests', () => { - let sandbox: SinonSandbox; - let mockedLogger: SinonStubbedInstance; - - const _token: Token = validateTokenFromString('secret-token:PIPeJGUt7c00ENn8a5uDlc'); - - beforeEach(() => { - sandbox = createSandbox(); - - mockedLogger = sandbox.createStubInstance(Logger); - Container.set(Logger, mockedLogger); - - Container.get(WebSdkConfiguration).setApiHost('http://ember-nexus-dev-api'); - }); - - afterEach(() => { - sandbox.restore(); - Container.reset(); - }); - - it('should load token', async () => { - Container.get(WebSdkConfiguration).setToken(_token); - - const token = await Container.get(GetTokenEndpoint).getToken(); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/token .', - ); - - expect(token).to.have.keys('id', 'type', 'data'); - expect(token).to.not.have.keys('start', 'end'); - expect(token.id).to.equal('e3b81351-fe0c-4f8f-ad22-78b6157edde8'); - expect(token.type).to.equal('Token'); - expect(Object.keys(token.data)).to.have.lengthOf(3); - }); - - it('should throw error 401 if token is invalid', async () => { - Container.get(WebSdkConfiguration).setToken(validateTokenFromString('secret-token:IdoNotWorkLol')); - - await expect(Container.get(GetTokenEndpoint).getToken()).to.eventually.be.rejected.and.deep.include({ - category: 'server', - title: 'Unauthorized', - detail: - "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", - status: 401, - }); - - assert.calledOnceWithExactly( - mockedLogger.debug, - 'Executing HTTP GET request against url http://ember-nexus-dev-api/token .', - ); - - assert.calledOnceWithExactly(mockedLogger.error, match.object); - }); -}); From 78b327d7d6ed16d363eee91f9496802a7582c65a Mon Sep 17 00:00:00 2001 From: Syndesi Date: Thu, 21 Mar 2024 08:51:56 +0000 Subject: [PATCH 3/3] Fix CI task names. --- .github/workflows/ci-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index e15fee7..82aa59f 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -74,7 +74,7 @@ jobs: ${{ runner.os }}-node-v${{ matrix.node-version }}- - name: Install dependencies run: yarn install --dev - - name: Run syntax linter + - name: Run unit tests run: yarn test:unit test-feature: @@ -101,5 +101,5 @@ jobs: ${{ runner.os }}-node-v${{ matrix.node-version }}- - name: Install dependencies run: yarn install --dev - - name: Run syntax linter + - name: Run feature tests run: yarn test:feature