-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for message.examples (#176)
- Loading branch information
Showing
14 changed files
with
214 additions
and
1,960 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { getExamplesFromSpec } from '../getExamplesFromSpec'; | ||
|
||
describe('getExamplesFromSpec', () => { | ||
test('should return headers', () => { | ||
const result = getExamplesFromSpec( | ||
[ | ||
{ | ||
headers: { | ||
header1: 1, | ||
}, | ||
payload: { | ||
prop1: 1, | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
header2: 2, | ||
}, | ||
payload: { | ||
prop2: 2, | ||
}, | ||
}, | ||
], | ||
'headers', | ||
); | ||
expect(result).toEqual([ | ||
{ | ||
header1: 1, | ||
}, | ||
{ | ||
header2: 2, | ||
}, | ||
]); | ||
}); | ||
|
||
test('should return payload', () => { | ||
const result = getExamplesFromSpec( | ||
[ | ||
{ | ||
headers: { | ||
header1: 1, | ||
}, | ||
payload: { | ||
prop1: 1, | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
header2: 2, | ||
}, | ||
payload: { | ||
prop2: 2, | ||
}, | ||
}, | ||
], | ||
'payload', | ||
); | ||
expect(result).toEqual([ | ||
{ | ||
prop1: 1, | ||
}, | ||
{ | ||
prop2: 2, | ||
}, | ||
]); | ||
}); | ||
|
||
test('should return payload and no undefined', () => { | ||
const result = getExamplesFromSpec( | ||
[ | ||
{ | ||
headers: { | ||
header1: 1, | ||
}, | ||
payload: { | ||
prop1: 1, | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
header2: 2, | ||
}, | ||
}, | ||
], | ||
'payload', | ||
); | ||
expect(result).toEqual([ | ||
{ | ||
prop1: 1, | ||
}, | ||
]); | ||
}); | ||
}); |
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,6 @@ | ||
import { Example } from '../types'; | ||
|
||
export type Type = 'payload' | 'headers'; | ||
|
||
export const getExamplesFromSpec = (examples: Example[], type: Type) => | ||
(examples.map(el => el[type]).filter(Boolean) as any) as object[]; |
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
Oops, something went wrong.