Files
shields/services/gitlab/gitlab-merge-requests.spec.js
dependabot[bot] b9d96755ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 (#9357)
* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* reformat all the things (prettier 3)

* update tests to await calls to prettier.format()

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: chris48s <git@chris-shaw.dev>
2023-07-10 09:27:51 +00:00

93 lines
2.5 KiB
JavaScript

import { test, given } from 'sazerac'
import nock from 'nock'
import { expect } from 'chai'
import { cleanUpNockAfterEach, defaultContext } from '../test-helpers.js'
import GitlabMergeRequests from './gitlab-merge-requests.service.js'
describe('GitlabMergeRequests', function () {
test(GitlabMergeRequests.render, () => {
given({ variant: 'open', mergeRequestCount: 1399 }).expect({
label: 'merge requests',
message: '1.4k open',
color: 'blue',
})
given({ variant: 'open', raw: '-raw', mergeRequestCount: 1399 }).expect({
label: 'open merge requests',
message: '1.4k',
color: 'blue',
})
given({
variant: 'open',
labels: 'discussion,enhancement',
mergeRequestCount: 15,
}).expect({
label: 'discussion,enhancement merge requests',
message: '15 open',
color: 'blue',
})
given({
variant: 'open',
raw: '-raw',
labels: 'discussion,enhancement',
mergeRequestCount: 15,
}).expect({
label: 'open discussion,enhancement merge requests',
message: '15',
color: 'blue',
})
given({ variant: 'open', mergeRequestCount: 0 }).expect({
label: 'merge requests',
message: '0 open',
color: 'blue',
})
given({ variant: 'open', mergeRequestCount: 10001 }).expect({
label: 'merge requests',
message: 'more than 10k open',
color: 'blue',
})
})
describe('auth', function () {
cleanUpNockAfterEach()
const fakeToken = 'abc123'
const config = {
public: {
services: {
gitlab: {
authorizedOrigins: ['https://gitlab.com'],
},
},
},
private: {
gitlab_token: fakeToken,
},
}
it('sends the auth information as configured', async function () {
const scope = nock('https://gitlab.com/')
.get(
'/api/v4/projects/foo%2Fbar/merge_requests?state=opened&page=1&per_page=1',
)
// This ensures that the expected credentials are actually being sent with the HTTP request.
// Without this the request wouldn't match and the test would fail.
.matchHeader('Authorization', `Bearer ${fakeToken}`)
.reply(200, {}, { 'x-total': '100', 'x-page': '1' })
expect(
await GitlabMergeRequests.invoke(
defaultContext,
config,
{ project: 'foo/bar', variant: 'open' },
{},
),
).to.deep.equal({
label: 'merge requests',
message: '100 open',
color: 'blue',
})
scope.done()
})
})
})