-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 443 adding tests for gateways services and models (#496)
- Loading branch information
Showing
52 changed files
with
1,004 additions
and
144 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
File renamed without changes.
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,18 @@ | ||
export enum Categories { | ||
Home = 'home', | ||
Test = 'test', | ||
Trace = 'trace', | ||
TraceDetail = 'trace-detail', | ||
TestResults = 'test-results', | ||
SpanDetail = 'span-detail', | ||
Assertion = 'assertion', | ||
} | ||
|
||
export enum Labels { | ||
Button = 'button', | ||
Link = 'link', | ||
Modal = 'modal', | ||
Table = 'table', | ||
Form = 'form', | ||
Tab = 'tab', | ||
} |
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,41 @@ | ||
import {endpoints} from '../../redux/apis/Test.api'; | ||
import AssertionGateway from '../Assertion.gateway'; | ||
|
||
const {createAssertion, getAssertions, updateAssertion} = endpoints; | ||
|
||
jest.mock('../../redux/apis/Test.api', () => { | ||
const initiate = jest.fn(() => Promise.resolve()); | ||
|
||
return { | ||
endpoints: { | ||
createAssertion: {initiate}, | ||
getAssertions: {initiate}, | ||
updateAssertion: {initiate}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe('AssertionGateway', () => { | ||
it('should execute the getAssertions function', async () => { | ||
expect.assertions(1); | ||
await AssertionGateway.get('testId'); | ||
|
||
expect(getAssertions.initiate).toBeCalledWith('testId'); | ||
}); | ||
|
||
it('should execute the createAssertion function', async () => { | ||
expect.assertions(1); | ||
const assertion = {assertionId: 'assertionId', selectors: []}; | ||
await AssertionGateway.create('testId', assertion); | ||
|
||
expect(createAssertion.initiate).toBeCalledWith({testId: 'testId', assertion}); | ||
}); | ||
|
||
it('should execute the updateAssertion function', async () => { | ||
expect.assertions(1); | ||
const assertion = {assertionId: 'assertionId', selectors: []}; | ||
await AssertionGateway.update('testId', 'assertionId', assertion); | ||
|
||
expect(updateAssertion.initiate).toBeCalledWith({testId: 'testId', assertionId: 'assertionId', assertion}); | ||
}); | ||
}); |
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,21 @@ | ||
import LocalStorageGateway from '../LocalStorage.gateway'; | ||
|
||
const localStorage = LocalStorageGateway<{name: string}>('key'); | ||
|
||
describe('LocalStorageGateway', () => { | ||
it('should set a value and retrieve it afterwards', async () => { | ||
expect.assertions(1); | ||
const item = {name: 'test'}; | ||
localStorage.set(item); | ||
|
||
const value = localStorage.get(); | ||
|
||
expect(value).toEqual(item); | ||
}); | ||
|
||
it('should return undefined as key is not found', async () => { | ||
const value = localStorage.get('not-found'); | ||
|
||
expect(value).toEqual(undefined); | ||
}); | ||
}); |
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,48 @@ | ||
import {endpoints} from '../../redux/apis/Test.api'; | ||
import TestGateway from '../Test.gateway'; | ||
|
||
const {createTest, getTestById, getTestList, runTest} = endpoints; | ||
|
||
jest.mock('../../redux/apis/Test.api', () => { | ||
const initiate = jest.fn(() => Promise.resolve()); | ||
|
||
return { | ||
endpoints: { | ||
createTest: {initiate}, | ||
getTestById: {initiate}, | ||
getTestList: {initiate}, | ||
runTest: {initiate}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe('TestGateway', () => { | ||
it('should execute the create function', async () => { | ||
expect.assertions(1); | ||
const test = {name: 'test', description: 'test'}; | ||
await TestGateway.create(test); | ||
|
||
expect(createTest.initiate).toBeCalledWith(test); | ||
}); | ||
|
||
it('should execute the getById function', async () => { | ||
expect.assertions(1); | ||
await TestGateway.getById('testId'); | ||
|
||
expect(getTestById.initiate).toBeCalledWith('testId'); | ||
}); | ||
|
||
it('should execute the getList function', async () => { | ||
expect.assertions(1); | ||
await TestGateway.getList(); | ||
|
||
expect(getTestList.initiate).toBeCalledWith(); | ||
}); | ||
|
||
it('should execute the runTest function', async () => { | ||
expect.assertions(1); | ||
await TestGateway.run('testId'); | ||
|
||
expect(runTest.initiate).toBeCalledWith('testId'); | ||
}); | ||
}); |
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,47 @@ | ||
import {endpoints} from '../../redux/apis/Test.api'; | ||
import TestRunResultGateway from '../TestRunResult.gateway'; | ||
|
||
const {getResultById, getResultList, updateResult} = endpoints; | ||
|
||
jest.mock('../../redux/apis/Test.api', () => { | ||
const initiate = jest.fn(() => Promise.resolve()); | ||
|
||
return { | ||
endpoints: { | ||
getResultById: {initiate}, | ||
getResultList: {initiate}, | ||
updateResult: {initiate}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe('TestRunResultGateway', () => { | ||
it('should execute the get function', async () => { | ||
expect.assertions(1); | ||
await TestRunResultGateway.get('testId'); | ||
|
||
expect(getResultList.initiate).toBeCalledWith({testId: 'testId', take: 25, skip: 0}); | ||
}); | ||
|
||
it('should execute the getById function', async () => { | ||
expect.assertions(1); | ||
await TestRunResultGateway.getById('testId', 'resultId'); | ||
|
||
expect(getResultById.initiate).toBeCalledWith({testId: 'testId', resultId: 'resultId'}); | ||
}); | ||
|
||
it('should execute the update function', async () => { | ||
expect.assertions(1); | ||
const testAssertionResult = { | ||
assertionResultState: true, | ||
assertionResult: [], | ||
}; | ||
await TestRunResultGateway.update('testId', 'resultId', testAssertionResult); | ||
|
||
expect(updateResult.initiate).toBeCalledWith({ | ||
testId: 'testId', | ||
resultId: 'resultId', | ||
assertionResult: testAssertionResult, | ||
}); | ||
}); | ||
}); |
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
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,30 @@ | ||
import faker from '@faker-js/faker'; | ||
import {TestState} from '../../constants/TestRunResult.constants'; | ||
import {IMockFactory} from '../../types/Common.types'; | ||
import {IRawTestRunResult, ITestRunResult} from '../../types/TestRunResult.types'; | ||
import TestRunResult from '../TestRunResult.model'; | ||
import TraceMock from './Trace.mock'; | ||
|
||
const TestRunResultMock: IMockFactory<ITestRunResult, IRawTestRunResult> = () => ({ | ||
raw(data = {}) { | ||
return { | ||
resultId: faker.datatype.uuid(), | ||
testId: faker.datatype.uuid(), | ||
traceId: faker.datatype.uuid(), | ||
spanId: faker.datatype.uuid(), | ||
createdAt: faker.date.past().toISOString(), | ||
completedAt: faker.date.past().toISOString(), | ||
response: {}, | ||
trace: TraceMock.raw(), | ||
state: TestState.FINISHED, | ||
assertionResultState: true, | ||
assertionResult: [], | ||
...data, | ||
}; | ||
}, | ||
model(data = {}) { | ||
return TestRunResult(this.raw(data)); | ||
}, | ||
}); | ||
|
||
export default TestRunResultMock(); |
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,35 @@ | ||
import faker from '@faker-js/faker'; | ||
import {IMockFactory} from '../../types/Common.types'; | ||
import {IRawTrace, ITrace} from '../../types/Trace.types'; | ||
import Trace from '../Trace.model'; | ||
import SpanMock from './Span.mock'; | ||
|
||
const TraceMock: IMockFactory<ITrace, IRawTrace> = () => ({ | ||
raw(data = {}) { | ||
return { | ||
description: faker.random.words(), | ||
resourceSpans: [ | ||
{ | ||
resource: { | ||
attributes: [], | ||
}, | ||
instrumentationLibrarySpans: [ | ||
{ | ||
instrumentationLibrary: { | ||
version: String(faker.datatype.number()), | ||
name: faker.random.word(), | ||
}, | ||
spans: faker.datatype.array(faker.datatype.number({min: 2, max: 10})).map(() => SpanMock.raw()), | ||
}, | ||
], | ||
}, | ||
], | ||
...data, | ||
}; | ||
}, | ||
model(data = {}) { | ||
return Trace(this.raw(data)); | ||
}, | ||
}); | ||
|
||
export default TraceMock(); |
Oops, something went wrong.