refactor(GitHubCommitActivity): switch to v4/GraphQL API (#6959)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
64
services/github/github-commit-activity.spec.js
Normal file
64
services/github/github-commit-activity.spec.js
Normal file
@@ -0,0 +1,64 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { InvalidResponse } from '../index.js'
|
||||
import GitHubCommitActivity from './github-commit-activity.service.js'
|
||||
|
||||
describe('GitHubCommitActivity', function () {
|
||||
describe('transform', function () {
|
||||
it('throws InvalidResponse on invalid branch and null object', function () {
|
||||
expect(() =>
|
||||
GitHubCommitActivity.transform({
|
||||
data: { repository: { object: null } },
|
||||
})
|
||||
)
|
||||
.to.throw(InvalidResponse)
|
||||
.with.property('prettyMessage', 'invalid branch')
|
||||
})
|
||||
})
|
||||
describe('getIntervalQueryStartDate', function () {
|
||||
/** @type {sinon.SinonFakeTimers} */
|
||||
let clock
|
||||
beforeEach(function () {
|
||||
clock = sinon.useFakeTimers()
|
||||
})
|
||||
afterEach(function () {
|
||||
clock.restore()
|
||||
})
|
||||
|
||||
it('provides correct value for yearly interval', function () {
|
||||
clock.tick(new Date('2021-08-28T02:21:34.000Z').getTime())
|
||||
expect(
|
||||
GitHubCommitActivity.getIntervalQueryStartDate({
|
||||
interval: 'y',
|
||||
})
|
||||
).to.equal('2020-08-28T02:21:34.000Z')
|
||||
})
|
||||
|
||||
it('provides correct value for simple monthly interval', function () {
|
||||
clock.tick(new Date('2021-03-31T02:21:34.000Z').getTime())
|
||||
expect(
|
||||
GitHubCommitActivity.getIntervalQueryStartDate({
|
||||
interval: 'm',
|
||||
})
|
||||
).to.equal('2021-03-01T02:21:34.000Z')
|
||||
})
|
||||
|
||||
it('provides correct value for fun monthly interval', function () {
|
||||
clock.tick(new Date('2021-03-07T02:21:34.000Z').getTime())
|
||||
expect(
|
||||
GitHubCommitActivity.getIntervalQueryStartDate({
|
||||
interval: '4w',
|
||||
})
|
||||
).to.equal('2021-02-05T02:21:34.000Z')
|
||||
})
|
||||
|
||||
it('provides correct value for weekly interval', function () {
|
||||
clock.tick(new Date('2021-12-31T23:59:34.000Z').getTime())
|
||||
expect(
|
||||
GitHubCommitActivity.getIntervalQueryStartDate({
|
||||
interval: 'w',
|
||||
})
|
||||
).to.equal('2021-12-24T23:59:34.000Z')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user