- add test case to validate the tags transformer
This commit is contained in:
+35
-1
@@ -1,4 +1,5 @@
|
||||
import {filterTags, prepareAndSortTags, TagInfo} from '../src/pr-collector/tags'
|
||||
import { validateTransformer } from '../src/pr-collector/regexUtils'
|
||||
import {filterTags, prepareAndSortTags, TagInfo, transformTags} from '../src/pr-collector/tags'
|
||||
|
||||
jest.setTimeout(180000)
|
||||
|
||||
@@ -145,3 +146,36 @@ it('Should filter tags correctly using the regex (inverse)', async () => {
|
||||
|
||||
expect(filtered).toStrictEqual(`0.1.0-b01,1.0.0,1.0.0-a01,2.0.0,10.1.0,20.0.2`)
|
||||
})
|
||||
|
||||
|
||||
it('Should transform tags correctly using the regex', async () => {
|
||||
const tags: TagInfo[] = [
|
||||
{name: 'api-0.0.1', commit: ''},
|
||||
{name: 'api-0.0.1-rc01', commit: ''},
|
||||
{name: 'config-0.1.0', commit: ''},
|
||||
{name: '0.1.0-b01', commit: ''},
|
||||
{name: '2.0.0', commit: ''},
|
||||
{name: '10.1.0', commit: ''},
|
||||
{name: 'api-10.1.0-2', commit: ''},
|
||||
{name: '20.0.2', commit: ''}
|
||||
]
|
||||
|
||||
const tagResolver = {
|
||||
method: 'non-existing-method',
|
||||
transformer: {
|
||||
pattern: '(api\-)?(.+)',
|
||||
target: "$2"
|
||||
}
|
||||
}
|
||||
|
||||
const transformer = validateTransformer(tagResolver.transformer)
|
||||
if(transformer != null) {
|
||||
const transformed = transformTags(tags, transformer)
|
||||
.map(function (tag) {
|
||||
return tag.name
|
||||
})
|
||||
.join(',')
|
||||
|
||||
expect(transformed).toStrictEqual(`0.0.1,0.0.1-rc01,config-0.1.0,0.1.0-b01,2.0.0,10.1.0,10.1.0-2,20.0.2`)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -211,7 +211,7 @@ export function filterTags(tags: TagInfo[], tagResolver: TagResolver): TagInfo[]
|
||||
/**
|
||||
* Helper function to transform the tag name given the transformer
|
||||
*/
|
||||
function transformTags(tags: TagInfo[], transformer: RegexTransformer): TagInfo[] {
|
||||
export function transformTags(tags: TagInfo[], transformer: RegexTransformer): TagInfo[] {
|
||||
return tags.map(function (tag) {
|
||||
if (transformer.pattern) {
|
||||
const transformedName = tag.name.replace(transformer.pattern, transformer.target)
|
||||
|
||||
Reference in New Issue
Block a user