Skip to content

Commit 7744eaa

Browse files
committed
test: add new test cases for GitHub API schemas
1 parent 0b1a83b commit 7744eaa

File tree

2 files changed

+147
-3
lines changed

2 files changed

+147
-3
lines changed

__fixtures__/index.js

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,129 @@ const sampleGithubOrg = {
6565
secret_scanning_push_protection_custom_link_enabled: false
6666
}
6767

68+
// https://docs.github.com/en/rest/reference/repos#list-organization-repositories
69+
const sampleGithubListOrgRepos = [
70+
{
71+
id: 1296269,
72+
node_id: 'MDEwOlJlcG9zaXRvcnkxMjk2MjY5',
73+
name: 'Hello-World',
74+
full_name: 'octocat/Hello-World',
75+
owner: {
76+
login: 'octocat',
77+
id: 1,
78+
node_id: 'MDQ6VXNlcjE=',
79+
avatar_url: 'https://github.com/images/error/octocat_happy.gif',
80+
gravatar_id: '',
81+
url: 'https://api.github.com/users/octocat',
82+
html_url: 'https://github.com/octocat',
83+
followers_url: 'https://api.github.com/users/octocat/followers',
84+
following_url: 'https://api.github.com/users/octocat/following{/other_user}',
85+
gists_url: 'https://api.github.com/users/octocat/gists{/gist_id}',
86+
starred_url: 'https://api.github.com/users/octocat/starred{/owner}{/repo}',
87+
subscriptions_url: 'https://api.github.com/users/octocat/subscriptions',
88+
organizations_url: 'https://api.github.com/users/octocat/orgs',
89+
repos_url: 'https://api.github.com/users/octocat/repos',
90+
events_url: 'https://api.github.com/users/octocat/events{/privacy}',
91+
received_events_url: 'https://api.github.com/users/octocat/received_events',
92+
type: 'User',
93+
site_admin: false
94+
},
95+
private: false,
96+
html_url: 'https://github.com/octocat/Hello-World',
97+
description: 'This your first repo!',
98+
fork: false,
99+
url: 'https://api.github.com/repos/octocat/Hello-World',
100+
archive_url: 'https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}',
101+
assignees_url: 'https://api.github.com/repos/octocat/Hello-World/assignees{/user}',
102+
blobs_url: 'https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}',
103+
branches_url: 'https://api.github.com/repos/octocat/Hello-World/branches{/branch}',
104+
collaborators_url: 'https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}',
105+
comments_url: 'https://api.github.com/repos/octocat/Hello-World/comments{/number}',
106+
commits_url: 'https://api.github.com/repos/octocat/Hello-World/commits{/sha}',
107+
compare_url: 'https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}',
108+
contents_url: 'https://api.github.com/repos/octocat/Hello-World/contents/{+path}',
109+
contributors_url: 'https://api.github.com/repos/octocat/Hello-World/contributors',
110+
deployments_url: 'https://api.github.com/repos/octocat/Hello-World/deployments',
111+
downloads_url: 'https://api.github.com/repos/octocat/Hello-World/downloads',
112+
events_url: 'https://api.github.com/repos/octocat/Hello-World/events',
113+
forks_url: 'https://api.github.com/repos/octocat/Hello-World/forks',
114+
git_commits_url: 'https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}',
115+
git_refs_url: 'https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}',
116+
git_tags_url: 'https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}',
117+
git_url: 'git:github.com/octocat/Hello-World.git',
118+
issue_comment_url: 'https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}',
119+
issue_events_url: 'https://api.github.com/repos/octocat/Hello-World/issues/events{/number}',
120+
issues_url: 'https://api.github.com/repos/octocat/Hello-World/issues{/number}',
121+
keys_url: 'https://api.github.com/repos/octocat/Hello-World/keys{/key_id}',
122+
labels_url: 'https://api.github.com/repos/octocat/Hello-World/labels{/name}',
123+
languages_url: 'https://api.github.com/repos/octocat/Hello-World/languages',
124+
merges_url: 'https://api.github.com/repos/octocat/Hello-World/merges',
125+
milestones_url: 'https://api.github.com/repos/octocat/Hello-World/milestones{/number}',
126+
notifications_url: 'https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}',
127+
pulls_url: 'https://api.github.com/repos/octocat/Hello-World/pulls{/number}',
128+
releases_url: 'https://api.github.com/repos/octocat/Hello-World/releases{/id}',
129+
ssh_url: '[email protected]:octocat/Hello-World.git',
130+
stargazers_url: 'https://api.github.com/repos/octocat/Hello-World/stargazers',
131+
statuses_url: 'https://api.github.com/repos/octocat/Hello-World/statuses/{sha}',
132+
subscribers_url: 'https://api.github.com/repos/octocat/Hello-World/subscribers',
133+
subscription_url: 'https://api.github.com/repos/octocat/Hello-World/subscription',
134+
tags_url: 'https://api.github.com/repos/octocat/Hello-World/tags',
135+
teams_url: 'https://api.github.com/repos/octocat/Hello-World/teams',
136+
trees_url: 'https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}',
137+
clone_url: 'https://github.com/octocat/Hello-World.git',
138+
mirror_url: 'git:git.example.com/octocat/Hello-World',
139+
hooks_url: 'https://api.github.com/repos/octocat/Hello-World/hooks',
140+
svn_url: 'https://svn.github.com/octocat/Hello-World',
141+
homepage: 'https://github.com',
142+
language: null,
143+
forks_count: 9,
144+
stargazers_count: 80,
145+
watchers_count: 80,
146+
size: 108,
147+
default_branch: 'master',
148+
open_issues_count: 0,
149+
is_template: false,
150+
topics: [
151+
'octocat',
152+
'atom',
153+
'electron',
154+
'api'
155+
],
156+
has_issues: true,
157+
has_projects: true,
158+
has_wiki: true,
159+
has_pages: false,
160+
has_downloads: true,
161+
has_discussions: false,
162+
archived: false,
163+
disabled: false,
164+
visibility: 'public',
165+
pushed_at: '2011-01-26T19:06:43Z',
166+
created_at: '2011-01-26T19:01:12Z',
167+
updated_at: '2011-01-26T19:14:43Z',
168+
permissions: {
169+
admin: false,
170+
push: false,
171+
pull: true
172+
},
173+
security_and_analysis: {
174+
advanced_security: {
175+
status: 'enabled'
176+
},
177+
secret_scanning: {
178+
status: 'enabled'
179+
},
180+
secret_scanning_push_protection: {
181+
status: 'disabled'
182+
},
183+
secret_scanning_non_provider_patterns: {
184+
status: 'disabled'
185+
}
186+
}
187+
}
188+
]
189+
68190
module.exports = {
69-
sampleGithubOrg
191+
sampleGithubOrg,
192+
sampleGithubListOrgRepos
70193
}

__tests__/schemas.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { sampleGithubOrg } = require('../__fixtures__')
2-
const { validateGithubOrg } = require('../src/schemas')
1+
const { sampleGithubOrg, sampleGithubListOrgRepos } = require('../__fixtures__')
2+
const { validateGithubOrg, validateGithubListOrgRepos } = require('../src/schemas')
33

44
describe('schemas', () => {
55
describe('validateGithubOrg', () => {
@@ -17,4 +17,25 @@ describe('schemas', () => {
1717
expect(() => validateGithubOrg(invalidData)).toThrow()
1818
})
1919
})
20+
describe('validateGithubListOrgRepos', () => {
21+
test('Should not throw an error with valid data', () => {
22+
expect(() => validateGithubListOrgRepos(sampleGithubListOrgRepos)).not.toThrow()
23+
})
24+
25+
test('Should not throw with additional data', () => {
26+
const additionalData = [
27+
...sampleGithubListOrgRepos,
28+
{ ...sampleGithubListOrgRepos[0], additionalKey: 'value' }
29+
]
30+
expect(() => validateGithubListOrgRepos(additionalData)).not.toThrow()
31+
})
32+
33+
test('Should throw an error with invalid data', () => {
34+
const invalidData = [
35+
...sampleGithubListOrgRepos,
36+
{ ...sampleGithubListOrgRepos[0], id: '123' }
37+
]
38+
expect(() => validateGithubListOrgRepos(invalidData)).toThrow()
39+
})
40+
})
2041
})

0 commit comments

Comments
 (0)