unity-builder/src/model/image-tag.test.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-12-22 17:07:55 +00:00
import ImageTag from './image-tag';
2019-12-22 14:05:15 +00:00
describe('UnityImageVersion', () => {
const some = {
repository: 'test1',
name: 'test2',
version: '2099.9.f9f9',
2019-12-22 17:07:55 +00:00
platform: 'Stadia',
2019-12-22 14:05:15 +00:00
builderPlatform: '',
};
const defaults = {
repository: 'gableroux',
name: 'unity3d',
image: 'gableroux/unity3d',
};
describe('constructor', () => {
it('can be called', () => {
2019-12-22 17:07:55 +00:00
const { platform } = some;
expect(() => new ImageTag({ platform })).not.toThrow();
2019-12-22 14:05:15 +00:00
});
it('accepts parameters and sets the right properties', () => {
2019-12-22 17:07:55 +00:00
const image = new ImageTag(some);
2019-12-22 14:05:15 +00:00
expect(image.repository).toStrictEqual(some.repository);
expect(image.name).toStrictEqual(some.name);
expect(image.version).toStrictEqual(some.version);
2019-12-22 17:07:55 +00:00
expect(image.platform).toStrictEqual(some.platform);
2019-12-22 14:05:15 +00:00
expect(image.builderPlatform).toStrictEqual(some.builderPlatform);
});
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', version => {
expect(() => new ImageTag({ version, platform: some.platform })).not.toThrow();
});
test.each(['some version', '', 1, null])('throws for incorrect versions %p', version => {
2019-12-22 17:07:55 +00:00
const { platform } = some;
expect(() => new ImageTag({ version, platform })).toThrow();
2019-12-22 14:05:15 +00:00
});
test.each([undefined, 'nonExisting'])('throws for unsupported target %p', platform => {
expect(() => new ImageTag({ platform })).toThrow();
2019-12-22 14:05:15 +00:00
});
});
describe('toString', () => {
it('returns the correct version', () => {
2019-12-22 17:07:55 +00:00
const image = new ImageTag({ version: '2099.1.1111', platform: some.platform });
2019-12-22 14:05:15 +00:00
expect(image.toString()).toStrictEqual(`${defaults.image}:2099.1.1111`);
});
it('returns the specific build platform', () => {
2019-12-22 17:07:55 +00:00
const image = new ImageTag({ version: '2019.2.11f1', platform: 'WebGL' });
2019-12-22 14:05:15 +00:00
expect(image.toString()).toStrictEqual(`${defaults.image}:2019.2.11f1-webgl`);
});
it('returns no specific build platform for generic targetPlatforms', () => {
2019-12-22 17:07:55 +00:00
const image = new ImageTag({ platform: 'Stadia' });
2019-12-22 14:05:15 +00:00
expect(image.toString()).toStrictEqual(`${defaults.image}:2019.2.11f1`);
});
});
});