import { codeBlock } from 'common-tags';
import { Fixtures } from '~test/fixtures.ts';
import { CachedMavenXml } from './schema.ts';
describe('modules/datasource/maven/schema', () => {
it('trims release metadata to the fields used by Renovate', () => {
const input = Fixtures.get('metadata.xml');
expect(CachedMavenXml.parse(input)).toEqual(codeBlock`
2.0.0
2.0.0
0.0.1
1.0.0
1.0.1
1.0.2
1.0.3-SNAPSHOT
1.0.4-SNAPSHOT
1.0.5-SNAPSHOT
2.0.0
`);
});
it('trims snapshot metadata to the fields used by Renovate', () => {
const input = Fixtures.get('metadata-snapshot-version.xml');
expect(CachedMavenXml.parse(input)).toEqual(codeBlock`
1.0.3-SNAPSHOT
20200101.010003
3
`);
});
it('trims pom files to the fields used by Renovate', () => {
const input = codeBlock`
org.example
package
Package Name
Package description
https://package.example.org/about
scm:git:https://github.com/example/package
org.relocated
package-new
2.0.0
Moved
org.parent
package-parent
1.2.3
`;
expect(CachedMavenXml.parse(input)).toEqual(codeBlock`
org.example
https://package.example.org/about
scm:git:https://github.com/example/package
org.relocated
package-new
2.0.0
Moved
org.parent
package-parent
1.2.3
`);
});
it('preserves empty relocation tags', () => {
const input = codeBlock`
package
Package Name
`;
expect(CachedMavenXml.parse(input)).toEqual(codeBlock`
`);
});
it('passes through unknown XML unchanged', () => {
const input = 'test';
expect(CachedMavenXml.parse(input)).toBe(input);
});
it('passes through prefixed pom XML unchanged', () => {
const input =
'https://package.example.org/about';
expect(CachedMavenXml.parse(input)).toBe(input);
});
it('passes through pom XML when no retained fields are present', () => {
const input = 'package';
expect(CachedMavenXml.parse(input)).toBe(input);
});
it('passes through metadata XML when no retained fields are present', () => {
const input = 'org.example';
expect(CachedMavenXml.parse(input)).toBe(input);
});
it('passes through invalid XML unchanged', () => {
const input = '';
expect(CachedMavenXml.parse(input)).toBe(input);
});
});