-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix MetadataFiller to use provided schemaVersion and producedBy (#169)
- Loading branch information
Showing
2 changed files
with
63 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { CommonMetadataFiller } from './MetadataFiller' | ||
|
||
const TEST_MESSAGE = { | ||
type: 'test.message', | ||
} | ||
|
||
const EVENT_DEFINITION = { | ||
schemaVersion: '0.0.0' | ||
} | ||
|
||
const SERVICE_ID = 'myServiceId' | ||
|
||
describe('MetadataFiller', () => { | ||
describe('produceMetadata', () => { | ||
let filler: CommonMetadataFiller | ||
|
||
beforeAll(() => { | ||
filler = new CommonMetadataFiller({ serviceId: SERVICE_ID }) | ||
}) | ||
|
||
it('Autofills metadata if not provided', () => { | ||
// When | ||
const metadata = filler.produceMetadata(TEST_MESSAGE, EVENT_DEFINITION) | ||
|
||
// Then | ||
expect(metadata.schemaVersion).toEqual(EVENT_DEFINITION.schemaVersion) | ||
expect(metadata.producedBy).toEqual(SERVICE_ID) | ||
expect(metadata.originatedFrom).toEqual(SERVICE_ID) | ||
expect(metadata.correlationId).toEqual(expect.any(String)) | ||
}) | ||
|
||
it('Autofills metadata if not provided and fallsback to default schema version if not in event definition', () => { | ||
// When | ||
const metadata = filler.produceMetadata(TEST_MESSAGE, {}) | ||
|
||
// Then | ||
expect(metadata.schemaVersion).toEqual('1.0.0') | ||
expect(metadata.producedBy).toEqual(SERVICE_ID) | ||
expect(metadata.originatedFrom).toEqual(SERVICE_ID) | ||
expect(metadata.correlationId).toEqual(expect.any(String)) | ||
}) | ||
|
||
it('Applies provided metadata', () => { | ||
// Given | ||
const providedMetadata = { | ||
schemaVersion: '2.0.0', | ||
producedBy: 'producer', | ||
originatedFrom: 'source', | ||
correlationId: 'myCorrelationId', | ||
} | ||
|
||
// When | ||
const metadata = filler.produceMetadata(TEST_MESSAGE, EVENT_DEFINITION, providedMetadata) | ||
|
||
// Then | ||
expect(metadata).toEqual(providedMetadata) | ||
}) | ||
}) | ||
}) |
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