Skip to content

Commit

Permalink
Add tests for SnapcraftVersion.transform
Browse files Browse the repository at this point in the history
  • Loading branch information
jNullj committed Mar 8, 2024
1 parent b54f1e6 commit 29dd792
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions services/snapcraft/snapcraft-version.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { expect } from 'chai'
import { test, given } from 'sazerac'
import _ from 'lodash'
import { NotFound } from '../index.js'
import SnapcraftVersion from './snapcraft-version.service.js'

describe('SnapcraftVersion', function () {
const exampleChannel = {
channel: {
architecture: 'amd64',
risk: 'stable',
track: 'latest',
},
version: '1.2.3',
}
const exampleArchChange = _.merge(_.cloneDeep(exampleChannel), {
channel: { architecture: 'arm64' },
version: '2.3.4',
})
const exampleTrackChange = _.merge(_.cloneDeep(exampleChannel), {
channel: { track: 'beta' },
version: '3.4.5',
})
const exampleRiskChange = _.merge(_.cloneDeep(exampleChannel), {
channel: { risk: 'edge' },
version: '5.4.6',
})
const testApiData = {
'channel-map': [
exampleChannel,
exampleArchChange,
exampleTrackChange,
exampleRiskChange,
],
}

test(SnapcraftVersion.prototype.transform, () => {
given(
testApiData,
exampleChannel.channel.track,
exampleChannel.channel.risk,
exampleChannel.channel.architecture,
).expect(exampleChannel)
// change arch
given(
testApiData,
exampleChannel.channel.track,
exampleChannel.channel.risk,
exampleArchChange.channel.architecture,
).expect(exampleArchChange)
// change track
given(
testApiData,
exampleTrackChange.channel.track,
exampleChannel.channel.risk,
exampleChannel.channel.architecture,
).expect(exampleTrackChange)
// change risk
given(
testApiData,
exampleChannel.channel.track,
exampleRiskChange.channel.risk,
exampleChannel.channel.architecture,
).expect(exampleRiskChange)
})

it('throws NotFound error with missing arch', function () {
expect(() => {
SnapcraftVersion.prototype.transform(
testApiData,
exampleChannel.channel.track,
exampleChannel.channel.risk,
'missing',
)
})
.to.throw(NotFound)
.with.property('prettyMessage', 'arch not found')
})
it('throws NotFound error with missing track', function () {
expect(() => {
SnapcraftVersion.prototype.transform(
testApiData,
'missing',
exampleChannel.channel.risk,
exampleChannel.channel.architecture,
)
})
.to.throw(NotFound)
.with.property('prettyMessage', 'track not found')
})
it('throws NotFound error with missing risk', function () {
expect(() => {
SnapcraftVersion.prototype.transform(
testApiData,
exampleChannel.channel.track,
'missing',
exampleChannel.channel.architecture,
)
})
.to.throw(NotFound)
.with.property('prettyMessage', 'risk not found')
})
})

0 comments on commit 29dd792

Please sign in to comment.