Skip to content

Commit 0fe7dfb

Browse files
committed
chore: add tests for Tiles queue
1 parent a261957 commit 0fe7dfb

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Avoid cyclic imports when importing m365ExcelApp
2+
import '@/apps'
3+
4+
import { afterEach, describe, expect, it, vi } from 'vitest'
5+
6+
import tilesApp from '..'
7+
8+
const mocks = vi.hoisted(() => ({
9+
stepQueryResult: vi.fn(),
10+
}))
11+
12+
vi.mock('@/models/step', () => ({
13+
default: {
14+
query: vi.fn(() => ({
15+
findById: vi.fn(() => ({
16+
throwIfNotFound: mocks.stepQueryResult,
17+
})),
18+
})),
19+
},
20+
}))
21+
22+
describe('Queue config', () => {
23+
afterEach(() => {
24+
vi.restoreAllMocks()
25+
})
26+
27+
it('configures a delayable queue', () => {
28+
expect(tilesApp.queue.isQueueDelayable).toEqual(true)
29+
})
30+
31+
it('sets group ID to the file ID', async () => {
32+
mocks.stepQueryResult.mockResolvedValueOnce({
33+
parameters: {
34+
tableId: 'mock-table-id',
35+
},
36+
key: 'findSingleRow',
37+
appKey: 'tiles',
38+
})
39+
const groupConfig = await tilesApp.queue.getGroupConfigForJob({
40+
flowId: 'test-flow-id',
41+
stepId: 'test-step-id',
42+
executionId: 'test-step-id',
43+
})
44+
expect(groupConfig).toEqual({
45+
id: 'mock-table-id-findSingleRow',
46+
})
47+
})
48+
49+
it('sets group ID to null', async () => {
50+
mocks.stepQueryResult.mockResolvedValueOnce({
51+
parameters: {
52+
tableId: 'mock-table-id',
53+
},
54+
key: 'createRow',
55+
appKey: 'tiles',
56+
})
57+
const groupConfig = await tilesApp.queue.getGroupConfigForJob({
58+
flowId: 'test-flow-id',
59+
stepId: 'test-step-id',
60+
executionId: 'test-step-id',
61+
})
62+
expect(groupConfig).toEqual(null)
63+
})
64+
65+
it('sets group concurrency to 1', () => {
66+
expect(tilesApp.queue.groupLimits).toEqual({
67+
type: 'concurrency',
68+
concurrency: 1,
69+
})
70+
})
71+
72+
it('avoids bursting via a leaky bucket approach', () => {
73+
expect(tilesApp.queue.queueRateLimit.max).toEqual(1)
74+
})
75+
})

0 commit comments

Comments
 (0)