-
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.
Showing
13 changed files
with
198 additions
and
62 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
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,15 @@ | ||
import {createQueueItem} from "./create-queue-item"; | ||
import {createRequestAction} from "../create-request-action"; | ||
import {createAction} from "@reduxjs/toolkit"; | ||
|
||
describe('createQueueItem', () => { | ||
it('creates a queue item from a request action and adds priority', () => { | ||
const queueItem = createQueueItem(createRequestAction({type: 'test'}), 1); | ||
expect(queueItem.priority).toBe(1); | ||
}); | ||
|
||
it('creates a queue item from a request action creator and adds priority', () => { | ||
const queueItemCreator = createQueueItem(createRequestAction(createAction('test')), 1); | ||
expect(queueItemCreator().priority).toBe(1); | ||
}); | ||
}) |
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,39 @@ | ||
import {QueueMemberItem, QueueType} from "./queue.interface"; | ||
import {createQueueItem} from "./create-queue-item"; | ||
import {createRequestAction} from "../create-request-action"; | ||
import {QueueItem} from "./queue-item.interface"; | ||
import {QueueState} from "./queue-state.enum"; | ||
import {findItemInQueue} from "./find-item-in-queue.util"; | ||
|
||
describe('findItemInQueue', () => { | ||
let queue: QueueType, queueItems: QueueMemberItem[]; | ||
beforeEach(() => { | ||
const resolveMocks = []; | ||
const rejectMocks = []; | ||
queueItems = []; | ||
for (let i = 0; i < 3; i++) { | ||
resolveMocks.push(jest.fn()); | ||
rejectMocks.push(jest.fn()); | ||
const queueItem: QueueMemberItem = { | ||
...createQueueItem(createRequestAction({type: `startAction${i}`}, {type: `endAction${i}`}), i) as QueueItem, | ||
id: i, | ||
processingPromise: undefined, | ||
resolve: resolveMocks[i], | ||
reject: rejectMocks[i], | ||
} | ||
queueItems.push(queueItem); | ||
} | ||
queue = { | ||
items: queueItems, | ||
state: QueueState.WAITING | ||
}; | ||
}) | ||
it('locates an item in a queue', () => { | ||
const item = findItemInQueue(queue, queueItems[1].id); | ||
expect(item).toBe(queueItems[1]); | ||
}); | ||
it('returns null if no item is found', () => { | ||
const notFoundItem = findItemInQueue(queue, 54); | ||
expect(notFoundItem).toBe(null) | ||
}) | ||
}) |
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,14 @@ | ||
import {createQueueItem} from "./create-queue-item"; | ||
import {createRequestAction} from "../create-request-action"; | ||
import {isQueueItem} from "./is-queue-item.util"; | ||
|
||
describe('isQueueItem', () => { | ||
it('Checks if an item is a queue item', () => { | ||
const queueItem = createQueueItem(createRequestAction({type: 'test'}, {type: 'testResponse'})); | ||
expect(isQueueItem(queueItem)).toBe(true); | ||
const nonQueueItemRequest = createRequestAction({type: 'test2'}, {type: 'test2response'}); | ||
expect(isQueueItem(nonQueueItemRequest)).toBe(false); | ||
const nonQueueItem = {type: 'test3'}; | ||
expect(isQueueItem(nonQueueItem)).toBe(false); | ||
}) | ||
}); |
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,9 @@ | ||
import {RejectActionError} from "./reject-action-error"; | ||
|
||
describe('RejectActionError', () => { | ||
it('creates a RejectActionError instance', () => { | ||
const rejectActionError = new RejectActionError({type: 'test'}); | ||
expect(rejectActionError.message).toBe('Rejected action test'); | ||
expect(rejectActionError).toBeInstanceOf(Error); | ||
}) | ||
}) |
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,12 @@ | ||
import {TimeoutError} from "./timeout-error"; | ||
|
||
describe('TimeoutError', () => { | ||
it('Creates a timeout error class', () => { | ||
const timeoutError = new TimeoutError('test'); | ||
expect(timeoutError.name).toBe('TimeoutError'); | ||
expect(timeoutError.message).toBe('test'); | ||
expect(timeoutError).toBeInstanceOf(Error); | ||
const timeoutError2 = new TimeoutError(); | ||
expect(timeoutError2.message).toBe('Timed out promise'); | ||
}) | ||
}) |