Files
shields/services/github/github-commit-activity.tester.js
jNullj 67d935492d feat: Add author filter option for [GithubCommitActivity] (#9251)
* feat: Add author filter option for CommitActivity

Add a new filter option to [GithubCommitActivity], allowing users to filter the commit activity by a specific author.

To make the filter more explicit, The label display "commits by [author]" for the total amount of commits and "commit activity by [author]" for other intervals when an author filter is selected.

To maintain a clear and organized code structure, The filtered author is added as an argument and not to the shield path.

The request to find the number of commits by the author is made using the REST api rather then the GraphQL api to make it in 1 request rather then 2.

Resolves #9215

* fix: solve eslint errors

* Add tests for [GithubCommitActivity] filter by author

Add tests for the new filter by author feature.

* update [GithubCommitActivity] spec file for new author feat

Add test for new transformAuthorFilter function of GithubCommitActivity added for the author filter feature.

* Fix null string for label of GithubCommitActivity

* Update GithubCommitActivity example

* improve error handeling for GithubCommitActivity

The author filter error handling removed was redundent as it would never execute, there is no way to seperate branch not found from repo not found.

* update depricated functions

PR #9233 replaced errorsMessages with httpErrors.
This commit updates the new changes to stay up to date with that PR

* remove test for nonexisting error

this exception was removed in commit 9e358c8 and is not needed anymore

* Fixed test for commit activity unexisting repo

* Update example for GithubCommitActivity

Picked a user with commits in the repo as an example that would work

* Add test for invalid commit activity branch

Add test for REST API calls in commit activity branch

---------

Co-authored-by: jNullj <jNullj@users.noreply.github.com>
2023-06-15 19:20:16 +01:00

121 lines
3.3 KiB
JavaScript

import Joi from 'joi'
import {
isMetricOverTimePeriod,
isZeroOverTimePeriod,
isMetric,
} from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
const isCommitActivity = Joi.alternatives().try(
isMetricOverTimePeriod,
isZeroOverTimePeriod
)
const authorFilterUser = 'jnullj'
t.create('commit activity (total)').get('/t/badges/shields.json').expectBadge({
label: 'commits',
message: isMetric,
})
t.create('commit activity (total) by author')
.get(`/t/badges/shields.json?authorFilter=${authorFilterUser}`)
.expectBadge({
label: `commits by ${authorFilterUser}`,
message: isMetric,
})
t.create('commit activity (1 year)').get('/y/eslint/eslint.json').expectBadge({
label: 'commit activity',
message: isMetricOverTimePeriod,
})
t.create('commit activity (1 year) by author')
.get(`/y/badges/shields.json?authorFilter=${authorFilterUser}`)
.expectBadge({
label: `commit activity by ${authorFilterUser}`,
message: isMetricOverTimePeriod,
})
t.create('commit activity (1 month)').get('/m/eslint/eslint.json').expectBadge({
label: 'commit activity',
message: isMetricOverTimePeriod,
})
t.create('commit activity (1 month) by author')
.get(`/m/badges/shields.json?authorFilter=${authorFilterUser}`)
.expectBadge({
label: `commit activity by ${authorFilterUser}`,
message: isMetricOverTimePeriod,
})
t.create('commit activity (4 weeks)')
.get('/4w/eslint/eslint.json')
.expectBadge({
label: 'commit activity',
message: isMetricOverTimePeriod,
})
t.create('commit activity (4 weeks) by author')
.get(`/4w/badges/shields.json?authorFilter=${authorFilterUser}`)
.expectBadge({
label: `commit activity by ${authorFilterUser}`,
message: isMetricOverTimePeriod,
})
t.create('commit activity (1 week)').get('/w/eslint/eslint.json').expectBadge({
label: 'commit activity',
message: isCommitActivity,
})
t.create('commit activity (1 week) by author')
.get(`/w/badges/shields.json?authorFilter=${authorFilterUser}`)
.expectBadge({
label: `commit activity by ${authorFilterUser}`,
message: isCommitActivity,
})
t.create('commit activity (custom branch)')
.get('/y/badges/squint/main.json')
.expectBadge({
label: 'commit activity',
message: isCommitActivity,
})
t.create('commit activity (custom branch) by author')
.get(`/y/badges/squint/main.json?authorFilter=${authorFilterUser}`)
.expectBadge({
label: `commit activity by ${authorFilterUser}`,
message: isCommitActivity,
})
t.create('commit activity (repo not found)')
.get('/w/badges/helmets.json')
.expectBadge({
label: 'commit activity',
message: 'repo not found',
})
t.create('commit activity (invalid branch)')
.get('/w/badges/shields/invalidBranchName.json')
.expectBadge({
label: 'commit activity',
message: 'invalid branch',
})
// test for error handling of author filter as it uses REST and not GraphQL
t.create('commit activity (repo not found)')
.get('/w/badges/helmets.json?authorFilter=zaphod')
.expectBadge({
label: 'commit activity',
message: 'repo or branch not found',
})
t.create('commit activity (invalid branch)')
.get('/w/badges/shields/invalidBranchName.json?authorFilter=zaphod')
.expectBadge({
label: 'commit activity',
message: 'repo or branch not found',
})