-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
171 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
const _ = require('lodash'); | ||
const helper = require('./image'); | ||
const moment = require('moment'); | ||
|
||
const { extractImages } = helper; | ||
|
||
jest.mock('../../../logic/entities/Image', () => class { | ||
constructor(props) { | ||
Object.assign(this, props); | ||
} | ||
}); | ||
|
||
describe('helpers unit tests', () => { | ||
describe('images', () => { | ||
describe('#extractImages', () => { | ||
beforeAll(() => { | ||
helper.extractFieldsForImageEntity = jest.fn((image, tag) => ({ tag: tag.tag || tag })); | ||
}); | ||
|
||
it('should wrap data into array if only one image passed', () => { | ||
const image = { | ||
tags: [{ tag: 'test', registry: 'r.cfcr.io' }], | ||
}; | ||
expect(extractImages(image)).toEqual([{tag: 'test'}]); | ||
}); | ||
|
||
it('should extract image tags as separate images', () => { | ||
expect(extractImages([ | ||
{ | ||
tags: [{ tag: 'banana' }, { tag: 'beer', registry: 'r.cfcr.io' }], | ||
}, | ||
{ | ||
tags: [{ tag: 'banana' }, { tag: 'beer', registry: 'r.cfcr.io' }], | ||
}, | ||
])).toEqual([ | ||
{ tag: 'banana' }, | ||
{ tag: 'beer' }, | ||
{ tag: 'banana' }, | ||
{ tag: 'beer' }, | ||
]); | ||
}); | ||
|
||
it('should filter tags by registries', () => { | ||
expect(extractImages([ | ||
{ | ||
tags: [ | ||
{ tag: 'banana', registry: 'filtered' }, | ||
{ tag: 'beer', registry: 'r.cfcr.io' }, | ||
], | ||
}, | ||
{ | ||
tags: [ | ||
{ tag: 'banana', registry: 'r.cfcr.io' }, | ||
{ tag: 'beer', registry: 'filtered' }, | ||
], | ||
}, | ||
], ['r.cfcr.io'])).toEqual([ | ||
{ tag: 'beer' }, | ||
{ tag: 'banana' }, | ||
]); | ||
}); | ||
|
||
it('should filter images tagged as "volume"', () => { | ||
expect(extractImages([ | ||
{ | ||
tags: [ | ||
{ tag: 'volume' }, | ||
], | ||
}, | ||
])).toEqual([]); | ||
}); | ||
|
||
it('should add <none> literal to image if it has no tags', () => { | ||
expect(extractImages([ | ||
{ | ||
tags: [], | ||
}, | ||
])).toEqual([{ tag: '<none>' }]); | ||
}); | ||
|
||
it('should sort images by date created DESC', () => { | ||
helper.extractFieldsForImageEntity = jest.fn(({ created }) => ({ info: { created } })); | ||
const images = [ | ||
{ | ||
created: new Date('2019-04-22T14:30:18.742Z'), | ||
}, | ||
{ | ||
created: new Date('2019-04-22T14:40:18.741Z'), | ||
}, | ||
{ | ||
created: new Date('2019-04-22T14:45:18.742Z'), | ||
}, | ||
]; | ||
const extracted = extractImages(images); | ||
const extractedDates = _.map(extracted, i => i.info.created); | ||
const initialSortedDates = _.chain(images) | ||
.orderBy(['created'], ['desc']) | ||
.map(i => i.created) | ||
.value(); | ||
expect(extractedDates).toEqual(initialSortedDates); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -1547,11 +1547,10 @@ eslint-plugin-import@^2.8.0: | |
minimatch "^3.0.3" | ||
read-pkg-up "^2.0.0" | ||
|
||
eslint-plugin-mocha@^4.11.0: | ||
version "4.12.1" | ||
resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.12.1.tgz#dbacc543b178b4536ec5b19d7f8e8864d85404bf" | ||
dependencies: | ||
ramda "^0.25.0" | ||
eslint-plugin-jest@^22.4.1: | ||
version "22.4.1" | ||
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-22.4.1.tgz#a5fd6f7a2a41388d16f527073b778013c5189a9c" | ||
integrity sha512-gcLfn6P2PrFAVx3AobaOzlIEevpAEf9chTpFZz7bYfc7pz8XRv7vuKTIE4hxPKZSha6XWKKplDQ0x9Pq8xX2mg== | ||
|
||
eslint-restricted-globals@^0.1.1: | ||
version "0.1.1" | ||
|
@@ -4371,10 +4370,6 @@ [email protected]: | |
version "0.15.1" | ||
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.15.1.tgz#b227f79e9ff0acee1955d582f18681eb02c4dc2a" | ||
|
||
ramda@^0.25.0: | ||
version "0.25.0" | ||
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.25.0.tgz#8fdf68231cffa90bc2f9460390a0cb74a29b29a9" | ||
|
||
randomatic@^1.1.3: | ||
version "1.1.7" | ||
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c" | ||
|