Files
shields/services/gitlab/gitlab-license.tester.js
guoxudong a73026faa9 feat: add [gitlab]-helper for encapsulate docs and err (#8295)
* feat: add gitlab-helper for encapsulate docs and err

* update merge requests

* fix mr example

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2022-09-04 22:32:23 +00:00

70 lines
1.8 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('/gitlab-org/gitlab-foss.json').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}`,
})