-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
294 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { EmberNexus } from '~/EmberNexus'; | ||
import { Logger } from '~/Service/Logger'; | ||
import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; | ||
import { validateUuidFromString } from '~/Type/Definition/Uuid'; | ||
|
||
import { TestLogger } from '../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.get('http://mock-api/2ce13d4f-bd96-4b71-b4e7-d43bd9948836', () => { | ||
return HttpResponse.json( | ||
{ | ||
type: 'Data', | ||
id: '2ce13d4f-bd96-4b71-b4e7-d43bd9948836', | ||
data: { | ||
created: '2023-10-06T20:27:56+00:00', | ||
updated: '2023-10-06T20:27:56+00:00', | ||
name: 'Test Data', | ||
}, | ||
}, | ||
{ | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
}, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('EmberNexus should handle node request', async () => { | ||
mockServer.listen(); | ||
const uuid = validateUuidFromString('2ce13d4f-bd96-4b71-b4e7-d43bd9948836'); | ||
|
||
const emberNexus = new EmberNexus(); | ||
const node = await emberNexus.getElement(uuid); | ||
|
||
expect( | ||
testLogger.assertDebugHappened( | ||
'Executing HTTP GET request against url http://mock-api/2ce13d4f-bd96-4b71-b4e7-d43bd9948836 .', | ||
), | ||
).to.be.true; | ||
|
||
expect(node).to.have.keys('id', 'type', 'data'); | ||
expect(node).to.not.have.keys('start', 'end'); | ||
expect(node.id).to.equal(uuid); | ||
expect(node.type).to.equal('Data'); | ||
expect(node.data.created).to.be.instanceof(Date); | ||
expect(node.data.updated).to.be.instanceof(Date); | ||
expect(Object.keys(node.data)).to.have.lengthOf(3); | ||
|
||
mockServer.close(); | ||
}); |
57 changes: 57 additions & 0 deletions
57
test/Feature/EmberNexus/EmberNexusGetElementNodeWithCache.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { EmberNexus } from '~/EmberNexus'; | ||
import { Logger } from '~/Service/Logger'; | ||
import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; | ||
import { validateUuidFromString } from '~/Type/Definition/Uuid'; | ||
|
||
import { TestLogger } from '../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.get('http://mock-api/2ce13d4f-bd96-4b71-b4e7-d43bd9948836', () => { | ||
return HttpResponse.json( | ||
{ | ||
type: 'Data', | ||
id: '2ce13d4f-bd96-4b71-b4e7-d43bd9948836', | ||
data: { | ||
created: '2023-10-06T20:27:56+00:00', | ||
updated: '2023-10-06T20:27:56+00:00', | ||
name: 'Test Data', | ||
}, | ||
}, | ||
{ | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
}, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('EmberNexus should use the cache for repeated node requests', async () => { | ||
mockServer.listen(); | ||
const uuid = validateUuidFromString('2ce13d4f-bd96-4b71-b4e7-d43bd9948836'); | ||
|
||
const emberNexus = new EmberNexus(); | ||
const node1 = await emberNexus.getElement(uuid); | ||
const node2 = await emberNexus.getElement(uuid); | ||
|
||
expect( | ||
testLogger.assertDebugHappened( | ||
'Executing HTTP GET request against url http://mock-api/2ce13d4f-bd96-4b71-b4e7-d43bd9948836 .', | ||
), | ||
).to.be.true; | ||
|
||
expect(node1).to.be.deep.equal(node2); | ||
|
||
mockServer.close(); | ||
}); |
63 changes: 63 additions & 0 deletions
63
test/Feature/EmberNexus/EmberNexusGetElementRelation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { EmberNexus } from '~/EmberNexus'; | ||
import { Logger } from '~/Service/Logger'; | ||
import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; | ||
import { validateUuidFromString } from '~/Type/Definition/Uuid'; | ||
|
||
import { TestLogger } from '../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.get('http://mock-api/eb243613-832b-411a-a161-616cdd75e2f9', () => { | ||
return HttpResponse.json( | ||
{ | ||
type: 'RELATION', | ||
id: 'eb243613-832b-411a-a161-616cdd75e2f9', | ||
start: 'ab5a01aa-6a02-42a9-9613-69d9453d0064', | ||
end: '0b624f56-a8ed-43f0-a250-4a821679a51f', | ||
data: { | ||
created: '2023-10-06T20:27:56+00:00', | ||
updated: '2023-10-06T20:27:56+00:00', | ||
name: 'Test relation', | ||
}, | ||
}, | ||
{ | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
}, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('EmberNexus should handle relation request', async () => { | ||
mockServer.listen(); | ||
const uuid = validateUuidFromString('eb243613-832b-411a-a161-616cdd75e2f9'); | ||
|
||
const emberNexus = new EmberNexus(); | ||
const relation = await emberNexus.getElement(uuid); | ||
|
||
expect( | ||
testLogger.assertDebugHappened( | ||
'Executing HTTP GET request against url http://mock-api/eb243613-832b-411a-a161-616cdd75e2f9 .', | ||
), | ||
).to.be.true; | ||
|
||
expect(relation).to.have.keys('id', 'start', 'end', 'type', 'data'); | ||
expect(relation.id).to.equal(uuid); | ||
expect(relation.type).to.equal('RELATION'); | ||
expect(relation.data.created).to.be.instanceof(Date); | ||
expect(relation.data.updated).to.be.instanceof(Date); | ||
expect(Object.keys(relation.data)).to.have.lengthOf(3); | ||
|
||
mockServer.close(); | ||
}); |
59 changes: 59 additions & 0 deletions
59
test/Feature/EmberNexus/EmberNexusGetElementRelationWithCache.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { EmberNexus } from '~/EmberNexus'; | ||
import { Logger } from '~/Service/Logger'; | ||
import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; | ||
import { validateUuidFromString } from '~/Type/Definition/Uuid'; | ||
|
||
import { TestLogger } from '../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.get('http://mock-api/32893cda-42db-4287-ac00-e73f250e1eeb', () => { | ||
return HttpResponse.json( | ||
{ | ||
type: 'RELATION', | ||
id: '32893cda-42db-4287-ac00-e73f250e1eeb', | ||
start: 'ab5a01aa-6a02-42a9-9613-69d9453d0064', | ||
end: '0b624f56-a8ed-43f0-a250-4a821679a51f', | ||
data: { | ||
created: '2023-10-06T20:27:56+00:00', | ||
updated: '2023-10-06T20:27:56+00:00', | ||
name: 'Test relation', | ||
}, | ||
}, | ||
{ | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
}, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('EmberNexus should use the cache for repeated relation request', async () => { | ||
mockServer.listen(); | ||
const uuid = validateUuidFromString('32893cda-42db-4287-ac00-e73f250e1eeb'); | ||
|
||
const emberNexus = new EmberNexus(); | ||
const relation1 = await emberNexus.getElement(uuid); | ||
const relation2 = await emberNexus.getElement(uuid); | ||
|
||
expect( | ||
testLogger.assertDebugHappened( | ||
'Executing HTTP GET request against url http://mock-api/32893cda-42db-4287-ac00-e73f250e1eeb .', | ||
), | ||
).to.be.true; | ||
|
||
expect(relation1).to.be.deep.equal(relation2); | ||
|
||
mockServer.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters