Files
shields/services/gitlab/gitlab-license.tester.js
chris48s 10bf39632a migrate examples to openApi part 26; affects [gitlab] (#9752)
* replace failing 'other' test with a mock

* update pipeline/coverage 'not found' tests

* migrate gitlab from examples to openApi

* eat own tail
2023-12-30 17:38:31 +00:00

81 lines
2.0 KiB
JavaScript

import { licenseToColor } from '../licenses.js'
import { createServiceTester } from '../tester.js'
import { noToken } from '../test-helpers.js'
import _noGitLabToken from './gitlab-license.service.js'
export const t = await createServiceTester()
const noGitLabToken = noToken(_noGitLabToken)
const publicDomainLicenseColor = licenseToColor('MIT License')
const unknownLicenseColor = licenseToColor()
t.create('License')
.get('/guoxudong.io/shields-test/licenced-test.json')
.expectBadge({
label: 'license',
message: 'MIT License',
color: `${publicDomainLicenseColor}`,
})
t.create('License for repo without a license')
.get('/guoxudong.io/shields-test/no-license-test.json')
.expectBadge({
label: 'license',
message: 'not specified',
color: 'lightgrey',
})
t.create('Other license')
.get('/group/project.json')
.intercept(nock =>
nock('https://gitlab.com')
.get('/api/v4/projects/group%2Fproject?license=1')
.reply(200, {
license: {
name: 'Other',
},
}),
)
.expectBadge({
label: 'license',
message: 'Other',
color: unknownLicenseColor,
})
t.create('License for unknown repo')
.get('/user1/gitlab-does-not-have-this-repo.json')
.expectBadge({
label: 'license',
message: 'project not found',
color: 'red',
})
t.create('Mocking License')
.get('/group/project.json')
.intercept(nock =>
nock('https://gitlab.com')
.get('/api/v4/projects/group%2Fproject?license=1')
.reply(200, {
license: {
key: 'apache-2.0',
name: 'Apache License 2.0',
nickname: '',
html_url: 'http://choosealicense.com/licenses/apache-2.0/',
source_url: '',
},
}),
)
.expectBadge({
label: 'license',
message: 'Apache License 2.0',
color: unknownLicenseColor,
})
t.create('License (private repo)')
.skipWhen(noGitLabToken)
.get('/shields-ops-group/test.json')
.expectBadge({
label: 'license',
message: 'MIT License',
color: `${publicDomainLicenseColor}`,
})