forked from faucetsdn/udmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handling braoder set of incoming validation messages (#212)
- Loading branch information
1 parent
444ed3c
commit bb4aea4
Showing
9 changed files
with
235 additions
and
142 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
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
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
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
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
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
112 changes: 54 additions & 58 deletions
112
udmif/event-handler/src/__tests__/model/Validation.spec.ts
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 |
---|---|---|
@@ -1,68 +1,64 @@ | ||
import { Error } from "../../model/UdmiMessage"; | ||
import { Validation, ValidationBuilder } from "../../model/Validation"; | ||
import { Error, Status } from '../../model/UdmiMessage'; | ||
import { Validation, ValidationBuilder } from '../../model/Validation'; | ||
|
||
describe('Validation.ValidationBuilder', () => { | ||
const TIMESTAMP_ERROR: string = 'Validation timestamp can not be empty'; | ||
const VERSION_ERROR: string = 'Validation version can not be empty'; | ||
|
||
const CATEGORY_ERROR: string = 'Validation category can not be empty'; | ||
const MESSAGE_ERROR: string = 'Validation message can not be empty'; | ||
const TIMESTAMP_ERROR: string = 'Validation timestamp can not be empty'; | ||
const ERRORS_ERROR: string = 'Validation errors can not be empty'; | ||
let builder: ValidationBuilder; | ||
beforeEach(() => { | ||
builder = new ValidationBuilder(); | ||
}); | ||
|
||
let builder: ValidationBuilder; | ||
beforeEach(() => { | ||
builder = new ValidationBuilder(); | ||
}); | ||
test.each([undefined, null])('throws exception when timestamp is not provided', (timestamp: string) => { | ||
expect(() => { | ||
builder.timestamp(timestamp); | ||
}).toThrow(TIMESTAMP_ERROR); | ||
}); | ||
|
||
test.each([undefined, null])('throws exception when category is not provided', (category: string) => { | ||
expect(() => { | ||
builder.category(category); | ||
}).toThrow(CATEGORY_ERROR); | ||
}) | ||
test.each([undefined, null])('throws exception when version is not provided', (version: string) => { | ||
expect(() => { | ||
builder.version(version); | ||
}).toThrow(VERSION_ERROR); | ||
}); | ||
|
||
test.each([undefined, null])('throws exception when message is not provided', (message: string) => { | ||
expect(() => { | ||
builder.message(message); | ||
}).toThrow(MESSAGE_ERROR); | ||
}) | ||
test('build returns a Validation object', () => { | ||
const status: Status = { | ||
message: 'some-message', | ||
category: 'some-category', | ||
level: 500, | ||
timestamp: '2022-08-03T17:28:49Z', | ||
detail: 'some-detail', | ||
}; | ||
|
||
test.each([undefined, null])('throws exception when timestamp is not provided', (timestamp: string) => { | ||
expect(() => { | ||
builder.timestamp(timestamp); | ||
}).toThrow(TIMESTAMP_ERROR); | ||
}) | ||
const errors: Error[] = [ | ||
{ | ||
message: 'While converting to json node: 2 schema violations found', | ||
level: 500, | ||
category: 'category-x', | ||
}, | ||
]; | ||
|
||
test.each([undefined, null])('throws exception when errors are not provided', (error: Error[]) => { | ||
expect(() => { | ||
builder.errors(error); | ||
}).toThrow(ERRORS_ERROR); | ||
}) | ||
const output: Validation = builder | ||
.timestamp('2022-08-03T17:28:49Z') | ||
.version('1.0') | ||
.status(status) | ||
.category('some-category') | ||
.message('some-message') | ||
.detail('some-detail') | ||
.errors(errors) | ||
.build(); | ||
|
||
test('build returns a Validation object', () => { | ||
const expectedValidation: Validation = { | ||
timestamp: '2022-08-03T17:28:49Z', | ||
version: '1.0', | ||
status, | ||
category: 'some-category', | ||
message: 'some-message', | ||
detail: 'some-detail', | ||
errors, | ||
}; | ||
|
||
const output: Validation = builder | ||
.category('some-category') | ||
.message('some-message') | ||
.detail('some-detail') | ||
.timestamp('2022-08-03T17:28:49Z') | ||
.errors([{ | ||
message: "While converting to json node: 2 schema violations found", | ||
level: 500, | ||
category: "category-x" | ||
}]).build(); | ||
|
||
const expectedValidation: Validation = { | ||
category: 'some-category', | ||
message: 'some-message', | ||
detail: 'some-detail', | ||
timestamp: '2022-08-03T17:28:49Z', | ||
errors: [{ | ||
message: "While converting to json node: 2 schema violations found", | ||
level: 500, | ||
category: "category-x" | ||
}] | ||
}; | ||
|
||
expect(output).toEqual(expectedValidation); | ||
}) | ||
|
||
}); | ||
expect(output).toEqual(expectedValidation); | ||
}); | ||
}); |
Oops, something went wrong.