Skip to content

Commit fac558b

Browse files
committed
test: update failing tests
1 parent 6e83aba commit fac558b

File tree

1 file changed

+91
-53
lines changed

1 file changed

+91
-53
lines changed

src/v3/TraceManagerWithDraft.test.ts

+91-53
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ describe('TraceManager', () => {
144144
expect(report.duration).toBeNull()
145145
})
146146

147-
describe('transitionDraftToActive: report errors', () => {
148-
it('reports warning when calling `transitionDraftToActive` with no reporting opts when a draft trace has not yet been created', () => {
147+
describe('transitionDraftToActive()', () => {
148+
it('after a trace is active: reports warning', () => {
149149
const traceManager = new TraceManager({
150150
relationSchemas: { ticket: { ticketId: String } },
151151
reportFn,
@@ -164,21 +164,28 @@ describe('TraceManager', () => {
164164
},
165165
})
166166

167+
tracer.createDraft({
168+
variant: 'cold_boot',
169+
})
170+
167171
tracer.transitionDraftToActive({ relatedTo: { ticketId: '1' } })
172+
tracer.transitionDraftToActive({ relatedTo: { ticketId: '2' } })
168173

169174
expect(reportWarningFn).toHaveBeenCalledWith(
170175
expect.objectContaining({
171176
message: expect.stringContaining(
172-
'No current active trace when initializing',
177+
'You are trying to activate a trace that has already been activated',
173178
),
174179
}),
175180
expect.objectContaining({
176-
definition: expect.any(Object),
181+
definition: expect.objectContaining({
182+
name: 'ticket.basic-operation',
183+
}),
177184
}),
178185
)
179186
})
180187

181-
it('reports error when calling `transitionDraftToActive` when reporting with error', () => {
188+
it('after a trace is active and previouslyActivatedBehavior is "warn-and-continue": reports error and continues trace with new trace modification', () => {
182189
const traceManager = new TraceManager({
183190
relationSchemas: { ticket: { ticketId: String } },
184191
reportFn,
@@ -197,24 +204,45 @@ describe('TraceManager', () => {
197204
},
198205
})
199206

207+
tracer.createDraft({
208+
variant: 'cold_boot',
209+
})
210+
211+
tracer.transitionDraftToActive({ relatedTo: { ticketId: '1' } })
200212
tracer.transitionDraftToActive(
201-
{ relatedTo: { ticketId: '1' } },
202-
{ previouslyActivatedBehavior: 'error' },
213+
{ relatedTo: { ticketId: '2' } },
214+
{ previouslyActivatedBehavior: 'warn-and-continue' },
203215
)
204216

205-
expect(reportErrorFn).toHaveBeenCalledWith(
217+
// prettier-ignore
218+
const { spans } = getSpansFromTimeline<TicketIdRelationSchemasFixture>`
219+
Events: ${Render('Component', 0, {type: 'component-render-start'})}--${Render('Component', 50)}--${Render('end', 50,)}
220+
Time: ${0} ${50} ${100}
221+
`
222+
processSpans(spans, traceManager)
223+
224+
expect(reportWarningFn).toHaveBeenCalledWith(
206225
expect.objectContaining({
207226
message: expect.stringContaining(
208-
'No current active trace when initializing',
227+
'You are trying to activate a trace that has already been activated',
209228
),
210229
}),
211230
expect.objectContaining({
212-
definition: expect.any(Object),
231+
definition: expect.objectContaining({
232+
name: 'ticket.basic-operation',
233+
}),
213234
}),
214235
)
236+
237+
expect(reportFn).toHaveBeenCalled()
238+
const report = reportFn.mock.calls[0]![0]
239+
240+
expect(report.relatedTo).toEqual({
241+
ticketId: '2', // relatedTo successfully replaced
242+
})
215243
})
216244

217-
it('reports error when calling `transitionDraftToActive` before creating a Trace when reporting with error-and-continue', () => {
245+
it('after a trace is active and previouslyActivatedBehavior is "error-and-continue": reports error and continues trace with new trace modification', () => {
218246
const traceManager = new TraceManager({
219247
relationSchemas: { ticket: { ticketId: String } },
220248
reportFn,
@@ -233,60 +261,45 @@ describe('TraceManager', () => {
233261
},
234262
})
235263

264+
tracer.createDraft({
265+
variant: 'cold_boot',
266+
})
267+
268+
tracer.transitionDraftToActive({ relatedTo: { ticketId: '1' } })
236269
tracer.transitionDraftToActive(
237-
{ relatedTo: { ticketId: '1' } },
270+
{ relatedTo: { ticketId: '2' } },
238271
{ previouslyActivatedBehavior: 'error-and-continue' },
239272
)
240273

274+
// prettier-ignore
275+
const { spans } = getSpansFromTimeline<TicketIdRelationSchemasFixture>`
276+
Events: ${Render('Component', 0, {type: 'component-render-start'})}--${Render('Component', 50)}--${Render('end', 50,)}
277+
Time: ${0} ${50} ${100}
278+
`
279+
processSpans(spans, traceManager)
280+
241281
expect(reportErrorFn).toHaveBeenCalledWith(
242282
expect.objectContaining({
243283
message: expect.stringContaining(
244-
'No current active trace when initializing',
284+
'You are trying to activate a trace that has already been activated',
245285
),
246286
}),
247287
expect.objectContaining({
248-
definition: expect.any(Object),
288+
definition: expect.objectContaining({
289+
name: 'ticket.basic-operation',
290+
}),
249291
}),
250292
)
251-
})
252293

253-
it('reports error when calling `transitionDraftToActive` when reporting with error', () => {
254-
const traceManager = new TraceManager({
255-
relationSchemas: { ticket: { ticketId: String } },
256-
reportFn,
257-
generateId,
258-
reportErrorFn,
259-
reportWarningFn,
260-
})
294+
expect(reportFn).toHaveBeenCalled()
295+
const report = reportFn.mock.calls[0]![0]
261296

262-
const tracer = traceManager.createTracer({
263-
name: 'ticket.basic-operation',
264-
type: 'operation',
265-
relationSchemaName: 'ticket',
266-
requiredSpans: [{ name: 'end' }],
267-
variants: {
268-
cold_boot: { timeout: DEFAULT_COLDBOOT_TIMEOUT_DURATION },
269-
},
297+
expect(report.relatedTo).toEqual({
298+
ticketId: '2', // relatedTo successfully replaced
270299
})
271-
272-
tracer.transitionDraftToActive(
273-
{ relatedTo: { ticketId: '1' } },
274-
{ previouslyActivatedBehavior: 'warn-and-continue' },
275-
)
276-
277-
expect(reportWarningFn).toHaveBeenCalledWith(
278-
expect.objectContaining({
279-
message: expect.stringContaining(
280-
'No current active trace when initializing',
281-
),
282-
}),
283-
expect.objectContaining({
284-
definition: expect.any(Object),
285-
}),
286-
)
287300
})
288301

289-
it('reports warning when calling `transitionDraftToActive` with no report opts again after a trace is active', () => {
302+
it('after a trace is active and previouslyActivatedBehavior is "error": reports error and continues trace with original trace definition', () => {
290303
const traceManager = new TraceManager({
291304
relationSchemas: { ticket: { ticketId: String } },
292305
reportFn,
@@ -312,13 +325,13 @@ describe('TraceManager', () => {
312325
tracer.transitionDraftToActive({ relatedTo: { ticketId: '1' } })
313326
tracer.transitionDraftToActive(
314327
{ relatedTo: { ticketId: '2' } },
315-
{ previouslyActivatedBehavior: '' },
328+
{ previouslyActivatedBehavior: 'error' },
316329
)
317330

318-
expect(reportWarningFn).toHaveBeenCalledWith(
331+
expect(reportErrorFn).toHaveBeenCalledWith(
319332
expect.objectContaining({
320333
message: expect.stringContaining(
321-
'trace that has already been initialized',
334+
'You are trying to activate a trace that has already been activated',
322335
),
323336
}),
324337
expect.objectContaining({
@@ -327,9 +340,34 @@ describe('TraceManager', () => {
327340
}),
328341
}),
329342
)
330-
})
331343

332-
// add relatedTo was overridden (expected for the 2 continue actions) or not
344+
// prettier-ignore
345+
const { spans } = getSpansFromTimeline<TicketIdRelationSchemasFixture>`
346+
Events: ${Render('Component', 0, {type: 'component-render-start'})}--${Render('Component', 50)}--${Render('end', 50,)}
347+
Time: ${0} ${50} ${100}
348+
`
349+
processSpans(spans, traceManager)
350+
351+
expect(reportErrorFn).toHaveBeenCalledWith(
352+
expect.objectContaining({
353+
message: expect.stringContaining(
354+
'You are trying to activate a trace that has already been activated',
355+
),
356+
}),
357+
expect.objectContaining({
358+
definition: expect.objectContaining({
359+
name: 'ticket.basic-operation',
360+
}),
361+
}),
362+
)
363+
364+
expect(reportFn).toHaveBeenCalled()
365+
const report = reportFn.mock.calls[0]![0]
366+
367+
expect(report.relatedTo).toEqual({
368+
ticketId: '1', // relatedTo was not replaced!
369+
})
370+
})
333371
})
334372

335373
describe('interrupt()', () => {

0 commit comments

Comments
 (0)