@sprucelabs/mercury-chunking-emitter 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src/.spruce/features/permission.plugin.ts → build/.spruce/features/permission.plugin.d.ts} +1 -1
- package/build/.spruce/features/permission.plugin.js +5 -0
- package/build/.spruce/permissions/permissions.types.d.ts +7 -0
- package/build/.spruce/permissions/permissions.types.js +3 -0
- package/build/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.d.ts +3 -0
- package/build/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.js +25 -0
- package/build/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
- package/build/.spruce/schemas/fields/fieldClassMap.js +4 -0
- package/{src/.spruce/schemas/fields/fields.types.ts → build/.spruce/schemas/fields/fields.types.d.ts} +1 -1
- package/build/.spruce/schemas/fields/fields.types.js +2 -0
- package/build/.spruce/schemas/schemas.types.d.ts +33 -0
- package/build/.spruce/schemas/schemas.types.js +4 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/choice.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/choice.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/choice.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/link.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/link.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/link.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/location.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/location.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/location.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/message.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/message.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/message.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/organization.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/organization.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/organization.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/person.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/person.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/person.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/role.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/role.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/role.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/skill.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/skill.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/skill.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.js +5 -0
- package/build/chunkingEmitter/ChunkingEmitter.d.ts +30 -0
- package/build/chunkingEmitter/ChunkingEmitter.js +71 -0
- package/build/chunkingEmitter/MockChunkingEmitter.d.ts +23 -0
- package/build/chunkingEmitter/MockChunkingEmitter.js +54 -0
- package/build/chunkingEmitter/chunkFieldDefinition.d.ts +2 -0
- package/build/chunkingEmitter/chunkFieldDefinition.js +17 -0
- package/build/esm/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.d.ts +3 -0
- package/build/esm/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.js +23 -0
- package/build/esm/.spruce/schemas/schemas.types.d.ts +33 -0
- package/build/esm/.spruce/schemas/schemas.types.js +3 -0
- package/build/esm/chunkingEmitter/ChunkingEmitter.d.ts +30 -0
- package/build/esm/chunkingEmitter/ChunkingEmitter.js +81 -0
- package/build/esm/chunkingEmitter/MockChunkingEmitter.d.ts +23 -0
- package/build/esm/chunkingEmitter/MockChunkingEmitter.js +62 -0
- package/build/esm/chunkingEmitter/chunkFieldDefinition.d.ts +2 -0
- package/build/esm/chunkingEmitter/chunkFieldDefinition.js +10 -0
- package/{src/index.ts → build/esm/index.d.ts} +3 -3
- package/build/esm/index.js +1 -0
- package/build/esm/schemas/v2023_10_21/chunkPaging.builder.d.ts +15 -0
- package/build/esm/schemas/v2023_10_21/chunkPaging.builder.js +15 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +8 -0
- package/build/schemas/v2023_10_21/chunkPaging.builder.d.ts +15 -0
- package/build/schemas/v2023_10_21/chunkPaging.builder.js +17 -0
- package/package.json +7 -2
- package/.circleci/config.yml +0 -71
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -3
- package/.githooks/pre-push +0 -17
- package/.nvmrc +0 -1
- package/.vscode/launch.json +0 -58
- package/.vscode/settings.json +0 -70
- package/.vscode/tasks.json +0 -112
- package/CHANGELOG.md +0 -25
- package/release.config.js +0 -7
- package/src/.spruce/permissions/permissions.types.ts +0 -9
- package/src/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.ts +0 -29
- package/src/.spruce/schemas/fields/fieldClassMap.ts +0 -6
- package/src/.spruce/schemas/schemas.types.ts +0 -52
- package/src/__tests__/behavioral/ChunkingEmitter.test.ts +0 -290
- package/src/__tests__/behavioral/TestingChunkingEmitter.test.ts +0 -174
- package/src/__tests__/support/AbstractChunkingEmitterTest.ts +0 -54
- package/src/chunkingEmitter/ChunkingEmitter.ts +0 -107
- package/src/chunkingEmitter/MockChunkingEmitter.ts +0 -101
- package/src/chunkingEmitter/chunkFieldDefinition.ts +0 -12
- package/src/schemas/v2023_10_21/chunkPaging.builder.ts +0 -16
- package/tsconfig.dist.json +0 -36
- package/tsconfig.json +0 -40
- /package/{src → build}/.spruce/settings.json +0 -0
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { SchemaRegistry } from '@sprucelabs/schema'
|
|
2
|
-
import { SpruceSchemas } from '../../schemas.types'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const chunkPagingSchema: SpruceSchemas.ChunkingEmitter.v2023_10_21.ChunkPagingSchema = {
|
|
7
|
-
id: 'chunkPaging',
|
|
8
|
-
version: 'v2023_10_21',
|
|
9
|
-
namespace: 'ChunkingEmitter',
|
|
10
|
-
name: 'Chunk Paging',
|
|
11
|
-
fields: {
|
|
12
|
-
/** . */
|
|
13
|
-
'total': {
|
|
14
|
-
type: 'number',
|
|
15
|
-
isRequired: true,
|
|
16
|
-
options: undefined
|
|
17
|
-
},
|
|
18
|
-
/** . */
|
|
19
|
-
'current': {
|
|
20
|
-
type: 'number',
|
|
21
|
-
isRequired: true,
|
|
22
|
-
options: undefined
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
SchemaRegistry.getInstance().trackSchema(chunkPagingSchema)
|
|
28
|
-
|
|
29
|
-
export default chunkPagingSchema
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
-
/* eslint-disable no-redeclare */
|
|
3
|
-
|
|
4
|
-
export { SpruceSchemas } from '@sprucelabs/spruce-core-schemas/build/.spruce/schemas/core.schemas.types'
|
|
5
|
-
|
|
6
|
-
import { default as SchemaEntity } from '@sprucelabs/schema'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import * as SpruceSchema from '@sprucelabs/schema'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare module '@sprucelabs/spruce-core-schemas/build/.spruce/schemas/core.schemas.types' {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
namespace SpruceSchemas.ChunkingEmitter.v2023_10_21 {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
interface ChunkPaging {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'total': number
|
|
23
|
-
|
|
24
|
-
'current': number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface ChunkPagingSchema extends SpruceSchema.Schema {
|
|
28
|
-
id: 'chunkPaging',
|
|
29
|
-
version: 'v2023_10_21',
|
|
30
|
-
namespace: 'ChunkingEmitter',
|
|
31
|
-
name: 'Chunk Paging',
|
|
32
|
-
fields: {
|
|
33
|
-
/** . */
|
|
34
|
-
'total': {
|
|
35
|
-
type: 'number',
|
|
36
|
-
isRequired: true,
|
|
37
|
-
options: undefined
|
|
38
|
-
},
|
|
39
|
-
/** . */
|
|
40
|
-
'current': {
|
|
41
|
-
type: 'number',
|
|
42
|
-
isRequired: true,
|
|
43
|
-
options: undefined
|
|
44
|
-
},
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface ChunkPagingEntity extends SchemaEntity<SpruceSchemas.ChunkingEmitter.v2023_10_21.ChunkPagingSchema> {}
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import { EventName } from '@sprucelabs/mercury-types'
|
|
2
|
-
import { FieldDefinitions, buildSchema } from '@sprucelabs/schema'
|
|
3
|
-
import { eventFaker, fake } from '@sprucelabs/spruce-test-fixtures'
|
|
4
|
-
import { test, assert, errorAssert, generateId } from '@sprucelabs/test-utils'
|
|
5
|
-
import { chunkFieldDefinition } from '../../chunkingEmitter/chunkFieldDefinition'
|
|
6
|
-
import ChunkingEmitterImpl from '../../chunkingEmitter/ChunkingEmitter'
|
|
7
|
-
import AbstractChunkingEmitterTest from '../support/AbstractChunkingEmitterTest'
|
|
8
|
-
|
|
9
|
-
@fake.login()
|
|
10
|
-
export default class ChunkingEmitterTest extends AbstractChunkingEmitterTest {
|
|
11
|
-
private static fqen2: EventName
|
|
12
|
-
private static allTargetAndPayloads: any[] = []
|
|
13
|
-
private static hitCount: number
|
|
14
|
-
protected static emitter: SpyEmitter
|
|
15
|
-
private static readonly itemFieldDefinition: FieldDefinitions = {
|
|
16
|
-
type: 'raw',
|
|
17
|
-
isArray: true,
|
|
18
|
-
options: {
|
|
19
|
-
valueType: 'any',
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected static async beforeEach() {
|
|
24
|
-
await super.beforeEach()
|
|
25
|
-
|
|
26
|
-
ChunkingEmitterImpl.Class = SpyEmitter
|
|
27
|
-
|
|
28
|
-
this.hitCount = 0
|
|
29
|
-
this.fqen = 'test.test::v2021_01_01' as EventName
|
|
30
|
-
this.fqen2 = 'test2.test3::v2022_02_02' as EventName
|
|
31
|
-
|
|
32
|
-
this.allTargetAndPayloads = []
|
|
33
|
-
|
|
34
|
-
this.mixinTestContract()
|
|
35
|
-
|
|
36
|
-
await this.resetEmitterWithChunkSize(1)
|
|
37
|
-
|
|
38
|
-
await this.fakedClient.on(this.fqen, (targetAndPayload) => {
|
|
39
|
-
this.hitCount++
|
|
40
|
-
this.allTargetAndPayloads.push(targetAndPayload)
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@test()
|
|
45
|
-
protected static async throwsWithMissing() {
|
|
46
|
-
//@ts-ignore
|
|
47
|
-
const err = await assert.doesThrowAsync(() => ChunkingEmitterImpl.Emitter())
|
|
48
|
-
errorAssert.assertError(err, 'MISSING_PARAMETERS', {
|
|
49
|
-
parameters: ['client'],
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@test()
|
|
54
|
-
protected static async emitThrowsWithMissing() {
|
|
55
|
-
//@ts-ignore
|
|
56
|
-
const err = await assert.doesThrowAsync(() => this.emitter.emit())
|
|
57
|
-
errorAssert.assertError(err, 'MISSING_PARAMETERS', {
|
|
58
|
-
parameters: ['eventName', 'items', 'payloadKey'],
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@test()
|
|
63
|
-
protected static async emitsNothingIfPassedNoItems() {
|
|
64
|
-
await this.emitWithItems([])
|
|
65
|
-
assert.isFalse(this.wasEventEmitted)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@test()
|
|
69
|
-
protected static async emitsThePassedEvent() {
|
|
70
|
-
await this.emitWithItems([{ id: '1' }])
|
|
71
|
-
assert.isTrue(this.wasEventEmitted)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
@test('passes one item to payload', [{ id: '1' }])
|
|
75
|
-
@test('passes two items to payload', [{ id: '1' }, { id: '2' }])
|
|
76
|
-
protected static async passesThePayloadThroughUsingTheKeyPassed(
|
|
77
|
-
items: Record<string, any>[]
|
|
78
|
-
) {
|
|
79
|
-
await this.resetEmitterWithChunkSize(10)
|
|
80
|
-
await this.emitWithItems(items)
|
|
81
|
-
this.assertLastEmittedItemsEqual(items)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@test()
|
|
85
|
-
protected static async canPassToDifferentPayloadKey() {
|
|
86
|
-
this.payloadKey = 'items2'
|
|
87
|
-
const item = await this.emitWithOneItem()
|
|
88
|
-
assert.isEqualDeep(this.lastEmittedPayload?.items2, [item])
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@test()
|
|
92
|
-
protected static async emitsNameOfEventPassed() {
|
|
93
|
-
this.fqen = this.fqen2
|
|
94
|
-
|
|
95
|
-
let wasHit = false
|
|
96
|
-
await eventFaker.on(this.fqen2, () => {
|
|
97
|
-
wasHit = true
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
await this.emitWithOneItem()
|
|
101
|
-
assert.isTrue(wasHit)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@test('emits 2 chunks', 2)
|
|
105
|
-
@test('emits 3 chunks', 3)
|
|
106
|
-
protected static async emitsCorrectNumberOfChunks(total: number) {
|
|
107
|
-
const items = await this.emitWithTotalItems(total)
|
|
108
|
-
this.assertTotalEmits(total)
|
|
109
|
-
|
|
110
|
-
const expected = items.map((item) => [item])
|
|
111
|
-
assert.isEqualDeep(
|
|
112
|
-
this.allTargetAndPayloads.map((t) => t.payload.items),
|
|
113
|
-
expected
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
@test()
|
|
118
|
-
protected static async doesNotStopIfOneFails() {
|
|
119
|
-
let hitCount = 0
|
|
120
|
-
await eventFaker.on(this.fqen, () => {
|
|
121
|
-
hitCount++
|
|
122
|
-
if (hitCount === 2) {
|
|
123
|
-
throw new Error('Failed')
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
await this.emitWithTotalItems(10)
|
|
128
|
-
assert.isEqual(hitCount, 10)
|
|
129
|
-
this.assertTotalErrors(1)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
@test()
|
|
133
|
-
protected static async accuratelyTracksTotalErrors() {
|
|
134
|
-
await this.makeEventThrow()
|
|
135
|
-
await this.assertEveryEmitErrors()
|
|
136
|
-
await this.assertEveryEmitErrors()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
@test()
|
|
140
|
-
protected static async includesChuckingPlacementInPayloadForOneItem() {
|
|
141
|
-
await this.emitWithOneItem()
|
|
142
|
-
assert.isEqualDeep(this.lastEmittedPayload?.chunk, {
|
|
143
|
-
total: 1,
|
|
144
|
-
current: 0,
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
@test()
|
|
149
|
-
protected static async includesChuckingPlacementInPayloadForTwoItems() {
|
|
150
|
-
await this.emitWithTotalItems(2)
|
|
151
|
-
const expected = [
|
|
152
|
-
{ total: 2, current: 0 },
|
|
153
|
-
{ total: 2, current: 1 },
|
|
154
|
-
]
|
|
155
|
-
assert.isEqualDeep(
|
|
156
|
-
this.allTargetAndPayloads.map((t) => t.payload.chunk),
|
|
157
|
-
expected
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
@test()
|
|
162
|
-
protected static async includesTargetInEmit() {
|
|
163
|
-
this.fqen = generateId() as EventName
|
|
164
|
-
|
|
165
|
-
const payloadSchema = buildSchema({
|
|
166
|
-
id: generateId(),
|
|
167
|
-
fields: {
|
|
168
|
-
items: this.itemFieldDefinition,
|
|
169
|
-
chunk: chunkFieldDefinition(),
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
const targetSchema = buildSchema({
|
|
174
|
-
id: generateId(),
|
|
175
|
-
fields: {
|
|
176
|
-
personId: {
|
|
177
|
-
type: 'id',
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
this.mixinEventSignatures({
|
|
183
|
-
[this.fqen]: this.buildSignature(payloadSchema, targetSchema),
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
let passedTarget: Record<string, any> | undefined
|
|
187
|
-
|
|
188
|
-
//@ts-ignore
|
|
189
|
-
await eventFaker.on(this.fqen, ({ target }) => {
|
|
190
|
-
passedTarget = target
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
const target = { personId: generateId() }
|
|
194
|
-
await this.emitWithOneItem(target)
|
|
195
|
-
assert.isEqualDeep(passedTarget, target)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@test()
|
|
199
|
-
protected static async defaultsToChunkSizeOfTen() {
|
|
200
|
-
this.emitter = (await ChunkingEmitterImpl.Emitter({
|
|
201
|
-
client: this.fakedClient,
|
|
202
|
-
})) as SpyEmitter
|
|
203
|
-
|
|
204
|
-
assert.isEqualDeep(this.emitter.getChunkSize(), 10)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
private static async makeEventThrow() {
|
|
208
|
-
await eventFaker.on(this.fqen, () => {
|
|
209
|
-
throw new Error('Failed')
|
|
210
|
-
})
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
private static assertTotalErrors(expected: number) {
|
|
214
|
-
assert.isEqual(this.emitter.getTotalErrors(), expected)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private static assertTotalEmits(total: number) {
|
|
218
|
-
assert.isEqual(this.hitCount, total)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
private static async emitWithTotalItems(total: number) {
|
|
222
|
-
const items = new Array(total).fill(0).map(() => this.generateItem())
|
|
223
|
-
await this.emitWithItems(items)
|
|
224
|
-
return items
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private static assertLastEmittedItemsEqual(items: Record<string, any>[]) {
|
|
228
|
-
assert.isEqualDeep(this.lastEmittedPayload?.items, items)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private static async resetEmitterWithChunkSize(chunkSize: number) {
|
|
232
|
-
this.emitter = (await ChunkingEmitterImpl.Emitter({
|
|
233
|
-
client: this.fakedClient,
|
|
234
|
-
chunkSize,
|
|
235
|
-
})) as SpyEmitter
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private static async emitWithOneItem(target?: Record<string, any>) {
|
|
239
|
-
const items = [this.generateItem()]
|
|
240
|
-
await this.emitWithItems(items, target)
|
|
241
|
-
return items[0]
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
private static get lastEmittedPayload() {
|
|
245
|
-
return this.lastTargetAndPayload?.payload
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
private static mixinTestContract() {
|
|
249
|
-
const eventSignatures = {
|
|
250
|
-
[this.fqen]: this.eventSignature,
|
|
251
|
-
[this.fqen2]: this.eventSignature,
|
|
252
|
-
}
|
|
253
|
-
this.mixinEventSignatures(eventSignatures)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
private static get eventSignature() {
|
|
257
|
-
const payload = buildSchema({
|
|
258
|
-
id: generateId(),
|
|
259
|
-
fields: {
|
|
260
|
-
items: this.itemFieldDefinition,
|
|
261
|
-
items2: this.itemFieldDefinition,
|
|
262
|
-
chunk: chunkFieldDefinition(),
|
|
263
|
-
},
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
return this.buildSignature(payload)
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
private static async assertEveryEmitErrors() {
|
|
270
|
-
await this.emitWithTotalItems(10)
|
|
271
|
-
this.assertTotalErrors(10)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
private static get lastTargetAndPayload() {
|
|
275
|
-
return this.allTargetAndPayloads[this.allTargetAndPayloads.length - 1]
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
private static get wasEventEmitted() {
|
|
279
|
-
return this.hitCount > 0
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
class SpyEmitter extends ChunkingEmitterImpl {
|
|
284
|
-
public constructor(options: any) {
|
|
285
|
-
super(options)
|
|
286
|
-
}
|
|
287
|
-
public getChunkSize() {
|
|
288
|
-
return this.chunkSize
|
|
289
|
-
}
|
|
290
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { EventName } from '@sprucelabs/mercury-types'
|
|
2
|
-
import {
|
|
3
|
-
FieldDefinitions,
|
|
4
|
-
SchemaFieldsByName,
|
|
5
|
-
buildSchema,
|
|
6
|
-
} from '@sprucelabs/schema'
|
|
7
|
-
import { fake } from '@sprucelabs/spruce-test-fixtures'
|
|
8
|
-
import { test, assert, generateId } from '@sprucelabs/test-utils'
|
|
9
|
-
import { chunkFieldDefinition } from '../../chunkingEmitter/chunkFieldDefinition'
|
|
10
|
-
import ChunkingEmitterImpl from '../../chunkingEmitter/ChunkingEmitter'
|
|
11
|
-
import MockChunkingEmitter from '../../chunkingEmitter/MockChunkingEmitter'
|
|
12
|
-
import AbstractChunkingEmitterTest from '../support/AbstractChunkingEmitterTest'
|
|
13
|
-
|
|
14
|
-
@fake.login()
|
|
15
|
-
export default class TestingChunkingEmitterTest extends AbstractChunkingEmitterTest {
|
|
16
|
-
protected static emitter: MockChunkingEmitter
|
|
17
|
-
private static readonly itemsField: FieldDefinitions = {
|
|
18
|
-
type: 'raw',
|
|
19
|
-
isArray: true,
|
|
20
|
-
options: {
|
|
21
|
-
valueType: 'any',
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
protected static async beforeEach(): Promise<void> {
|
|
26
|
-
await super.beforeEach()
|
|
27
|
-
ChunkingEmitterImpl.Class = MockChunkingEmitter
|
|
28
|
-
this.fqen = generateId() as EventName
|
|
29
|
-
this.emitter = (await ChunkingEmitterImpl.Emitter({
|
|
30
|
-
client: this.fakedClient,
|
|
31
|
-
})) as MockChunkingEmitter
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@test()
|
|
35
|
-
protected static async canSetSpyClass() {
|
|
36
|
-
assert.isInstanceOf(this.emitter, MockChunkingEmitter)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@test()
|
|
40
|
-
protected static async knowsIfWasHit() {
|
|
41
|
-
assert.doesThrow(() => this.emitter.assertDidEmit())
|
|
42
|
-
await this.emit()
|
|
43
|
-
this.emitter.assertDidEmit()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@test()
|
|
47
|
-
protected static async knowsEventNamePassedToIt() {
|
|
48
|
-
await this.emit()
|
|
49
|
-
assert.doesThrow(() =>
|
|
50
|
-
this.emitter.assertDidEmitEventNamed(generateId() as EventName)
|
|
51
|
-
)
|
|
52
|
-
this.emitter.assertDidEmitEventNamed(this.fqen)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@test()
|
|
56
|
-
protected static async knowsItemsEmitted() {
|
|
57
|
-
const items = [this.generateItem(), this.generateItem()]
|
|
58
|
-
this.assertDidEmitItemsThrows(items)
|
|
59
|
-
await this.emitWithItems(items)
|
|
60
|
-
this.emitter.assertEmittedItems(items)
|
|
61
|
-
this.assertDidEmitItemsThrows([])
|
|
62
|
-
this.assertDidEmitItemsThrows([this.generateItem()])
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@test()
|
|
66
|
-
protected static async canResetFactoryClassReference() {
|
|
67
|
-
ChunkingEmitterImpl.reset()
|
|
68
|
-
assert.isFalsy(ChunkingEmitterImpl.Class)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@test()
|
|
72
|
-
protected static async canAssertPayloadKey() {
|
|
73
|
-
this.payloadKey = generateId()
|
|
74
|
-
await this.emit()
|
|
75
|
-
assert.doesThrow(() => this.emitter.assertDidEmitPayloadKey('wrong'))
|
|
76
|
-
this.emitter.assertDidEmitPayloadKey(this.payloadKey)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@test()
|
|
80
|
-
protected static async throwsIfEventSignatureIsBad() {
|
|
81
|
-
const sigWithoutChunking = this.buildSignatureWithPayloadFields({
|
|
82
|
-
items: this.itemsField,
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
const sigWithChunking = this.buildSignatureWithPayloadFields({
|
|
86
|
-
items: this.itemsField,
|
|
87
|
-
chunk: chunkFieldDefinition(),
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const fqenWithChunk = generateId() as EventName
|
|
91
|
-
this.mixinEventSignatures({
|
|
92
|
-
[this.fqen]: sigWithoutChunking,
|
|
93
|
-
[fqenWithChunk]: sigWithChunking,
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const fqen = this.fqen
|
|
97
|
-
this.assertSignatureDoesNotConformToChunk(fqen)
|
|
98
|
-
this.assertSignatureDoesConfirmToChunk(fqenWithChunk)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
@test()
|
|
102
|
-
protected static async throwsIfChunkIsThereButBad() {
|
|
103
|
-
this.assertChunkFieldThrowsWithBadMatch({
|
|
104
|
-
type: 'number',
|
|
105
|
-
})
|
|
106
|
-
this.assertChunkFieldThrowsWithBadMatch({
|
|
107
|
-
type: 'schema',
|
|
108
|
-
options: {
|
|
109
|
-
schema: buildSchema({
|
|
110
|
-
id: generateId(),
|
|
111
|
-
fields: {
|
|
112
|
-
test: {
|
|
113
|
-
type: 'number',
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
117
|
-
},
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@test()
|
|
122
|
-
protected static async canGetMockInstance() {
|
|
123
|
-
assert.isEqual(MockChunkingEmitter.getLastInstance(), this.emitter)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
@test()
|
|
127
|
-
protected static async throwsIfNoInstance() {
|
|
128
|
-
MockChunkingEmitter.reset()
|
|
129
|
-
assert.doesThrow(() => MockChunkingEmitter.getLastInstance())
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private static assertChunkFieldThrowsWithBadMatch(
|
|
133
|
-
chunkSig: FieldDefinitions
|
|
134
|
-
) {
|
|
135
|
-
const fqen = generateId() as EventName
|
|
136
|
-
const sig = this.buildSignatureWithPayloadFields({
|
|
137
|
-
items: this.itemsField,
|
|
138
|
-
chunk: chunkSig,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
this.mixinEventSignatures({
|
|
142
|
-
[fqen]: sig,
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
this.assertSignatureDoesNotConformToChunk(fqen)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
private static assertSignatureDoesConfirmToChunk(fqenWithChunk: EventName) {
|
|
149
|
-
this.emitter.assertEventHonorsChunkingSignature(fqenWithChunk)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
private static assertSignatureDoesNotConformToChunk(fqen: EventName) {
|
|
153
|
-
assert.doesThrow(() =>
|
|
154
|
-
this.emitter.assertEventHonorsChunkingSignature(fqen)
|
|
155
|
-
)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private static buildSignatureWithPayloadFields(fields: SchemaFieldsByName) {
|
|
159
|
-
return this.buildSignature(
|
|
160
|
-
buildSchema({
|
|
161
|
-
id: generateId(),
|
|
162
|
-
fields,
|
|
163
|
-
})
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private static assertDidEmitItemsThrows(items: { id: string }[]) {
|
|
168
|
-
assert.doesThrow(() => this.emitter.assertEmittedItems(items))
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
private static async emit() {
|
|
172
|
-
return this.emitWithItems([this.generateItem()])
|
|
173
|
-
}
|
|
174
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { MercuryTestClient } from '@sprucelabs/mercury-client'
|
|
2
|
-
import { EventName, EventSignaturesByName } from '@sprucelabs/mercury-types'
|
|
3
|
-
import { Schema } from '@sprucelabs/schema'
|
|
4
|
-
import { buildEmitTargetAndPayloadSchema } from '@sprucelabs/spruce-event-utils'
|
|
5
|
-
import { AbstractSpruceFixtureTest } from '@sprucelabs/spruce-test-fixtures'
|
|
6
|
-
import { generateId } from '@sprucelabs/test-utils'
|
|
7
|
-
import { ChunkingEmitter } from '../../chunkingEmitter/ChunkingEmitter'
|
|
8
|
-
|
|
9
|
-
export default abstract class AbstractChunkingEmitterTest extends AbstractSpruceFixtureTest {
|
|
10
|
-
protected static emitter: ChunkingEmitter
|
|
11
|
-
protected static fqen: EventName
|
|
12
|
-
protected static payloadKey: string
|
|
13
|
-
|
|
14
|
-
protected static async beforeEach() {
|
|
15
|
-
await super.beforeEach()
|
|
16
|
-
this.payloadKey = 'items'
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
protected static mixinEventSignatures(
|
|
20
|
-
eventSignatures: EventSignaturesByName
|
|
21
|
-
) {
|
|
22
|
-
const client = this.fakedClient as MercuryTestClient
|
|
23
|
-
client.mixinContract({
|
|
24
|
-
eventSignatures,
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
protected static buildSignature(payload: Schema, target?: Schema) {
|
|
29
|
-
return {
|
|
30
|
-
isGlobal: true,
|
|
31
|
-
emitPayloadSchema: buildEmitTargetAndPayloadSchema({
|
|
32
|
-
eventName: this.fqen,
|
|
33
|
-
payloadSchema: payload,
|
|
34
|
-
targetSchema: target,
|
|
35
|
-
}),
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
protected static async emitWithItems(
|
|
40
|
-
items: Record<string, unknown>[],
|
|
41
|
-
target?: Record<string, any>
|
|
42
|
-
) {
|
|
43
|
-
await this.emitter.emit({
|
|
44
|
-
eventName: this.fqen,
|
|
45
|
-
items,
|
|
46
|
-
payloadKey: this.payloadKey,
|
|
47
|
-
target,
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected static generateItem() {
|
|
52
|
-
return { id: generateId() }
|
|
53
|
-
}
|
|
54
|
-
}
|