Skip to content

Commit

Permalink
feat: Updated ./test/batcher.json.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Apr 9, 2024
1 parent 32ce710 commit 452f6a5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/batcher.json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,30 @@ describe('Batcher tests with JSON transport', function () {
await stub.mockReturnValue(() => call())
const spy = jest.fn(call)

batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[0]))
batcher.pushLogEntry(fixtures.logs[0])

function call () {
expect(spy).toHaveBeenCalledTimes(1)
}
await stub.mockRestore()
})
it('Should add same items in the same stream', function () {
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[0]))
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[0]))
batcher.pushLogEntry(fixtures.logs[0])
batcher.pushLogEntry(fixtures.logs[0])
expect(batcher.batch.streams.length).toBe(1)
})
it('Should add items with same labels in the same stream', function () {
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[1]))
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[2]))
batcher.pushLogEntry(fixtures.logs[1])
batcher.pushLogEntry(fixtures.logs[2])
expect(batcher.batch.streams.length).toBe(1)
})
it('Should add items with different labels in separate streams', function () {
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[0]))
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[2]))
batcher.pushLogEntry(fixtures.logs[0])
batcher.pushLogEntry(fixtures.logs[2])
expect(batcher.batch.streams.length).toBe(2)
})
it('Should replace timestamps with Date.now() if replaceTimestamp is enabled', function () {
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[1]))
batcher.pushLogEntry(fixtures.logs[1])

expect(batcher.batch.streams[0].entries[0].ts).toBe(
fixtures.logs[1].timestamp
Expand All @@ -84,15 +84,15 @@ describe('Batcher tests with JSON transport', function () {
options.replaceTimestamp = true
batcher = new Batcher(options)

batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[1]))
batcher.pushLogEntry(fixtures.logs[1])

expect(batcher.batch.streams[0].entries[0].ts).not.toBe(
fixtures.logs[1].timestamp
)
})
it('Should be able to clear the batch of streams', function () {
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[0]))
batcher.pushLogEntry(JSON.parse(fixtures.logs_mapped_before[2]))
batcher.pushLogEntry(fixtures.logs[0])
batcher.pushLogEntry(fixtures.logs[2])
expect(batcher.batch.streams.length).toBe(2)
batcher.clearBatch()
expect(batcher.batch.streams.length).toBe(0)
Expand All @@ -111,7 +111,7 @@ describe('Batcher tests with JSON transport', function () {
batcher.pushLogEntry(fixtures.logs[1])

expect(req.post.mock.calls[0][req.post.mock.calls[0].length - 1]).toBe(
JSON.stringify({ streams: [JSON.parse(fixtures.logs_mapped_after[1])] })
JSON.stringify({ streams: [fixtures.logs[1]] })
)
})
it('Should clear batch and resolve on successful send', async function () {
Expand All @@ -129,7 +129,7 @@ describe('Batcher tests with JSON transport', function () {
await batcher.sendBatchToLoki()

expect(req.post.mock.calls[0][req.post.mock.calls[0].length - 1]).toBe(
JSON.stringify({ streams: [JSON.parse(fixtures.logs_mapped_after[0])] })
JSON.stringify({ streams: [fixtures.logs[0]] })
)
expect(batcher.batch.streams.length).toBe(0)
})
Expand Down

0 comments on commit 452f6a5

Please sign in to comment.