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

68 lines
2.2 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);
});
it('throws for incorrect versions', () => {
2019-12-22 17:07:55 +00:00
const { platform } = some;
expect(() => new ImageTag({ version: 'some version', platform })).toThrow();
expect(() => new ImageTag({ version: '', platform })).toThrow();
expect(() => new ImageTag({ version: 1, platform })).toThrow();
expect(() => new ImageTag({ version: null, platform })).toThrow();
2019-12-22 14:05:15 +00:00
});
it('throws for incorrect or unsupported targets', () => {
2019-12-22 17:07:55 +00:00
expect(() => new ImageTag({ platform: undefined })).toThrow();
expect(() => new ImageTag({ platform: 'nonExisting' })).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`);
});
});
});