Skip to content

Commit

Permalink
test: GitHubProjectNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Oct 5, 2023
1 parent 1f3479e commit 2dfdf7e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 242 deletions.
32 changes: 32 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { expectType, expectNotType } from "tsd";
import { Octokit } from "@octokit/core";
import GitHubProject, {
GitHubProjectError,
GitHubProjectNotFoundError,
GitHubProjectUnknownFieldError,
GitHubProjectUnknownFieldOptionError,
GitHubProjectUpdateReadOnlyFieldError,
} from "./index";

export function smokeTest() {
Expand Down Expand Up @@ -655,6 +657,18 @@ export function testGitHubProjectError() {
expectType<string>(error.toHumanMessage());
}

export function testGitHubProjectNotFoundError() {
const details = {
owner: "owner",
number: 1,
};
const error = new GitHubProjectNotFoundError(details);

expectType<"GitHubProjectNotFoundError">(error.name);
expectType<typeof details>(error.details);
expectType<string>(error.toHumanMessage());
}

export function testGitHubProjectUnknownFieldError() {
const details = {
projectFieldNames: ["one", "two"],
Expand Down Expand Up @@ -688,3 +702,21 @@ export function testGitHubProjectUnknownFieldOptionError() {
expectType<typeof details>(error.details);
expectType<string>(error.toHumanMessage());
}

export function testGitHubProjectUpdateReadOnlyFieldError() {
const details = {
fields: [
{
id: "field id",
name: "field name",
userName: "user name",
userValue: "user value",
},
],
};
const error = new GitHubProjectUpdateReadOnlyFieldError(details);

expectType<"GitHubProjectUpdateReadOnlyFieldError">(error.name);
expectType<typeof details>(error.details);
expectType<string>(error.toHumanMessage());
}
5 changes: 4 additions & 1 deletion test/recorded/api.getProperties-project-not-found/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export function test(defaultTestProject) {
() => {
throw new Error("Should not resolve");
},
(error) => error
(error) => ({
error,
humanMessage: error.toHumanMessage(),
})
);
}
5 changes: 4 additions & 1 deletion test/recorded/getInstance-project-not-found/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export function test(defaultTestProject) {
() => {
throw new Error("Should not resolve");
},
(error) => error
(error) => ({
error,
humanMessage: error.toHumanMessage(),
})
);
}
250 changes: 10 additions & 240 deletions test/snapshots/recorded.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,130 +49,15 @@ Generated by [AVA](https://avajs.dev).

> Snapshot 1
GraphqlResponseError {
data: {
userOrOrganization: {
projectV2: null,
},
},
errors: [
{
locations: [
{
column: 9,
line: 5,
},
],
message: 'Could not resolve to a ProjectV2 with the number 99999.',
path: [
'userOrOrganization',
'projectV2',
],
type: 'NOT_FOUND',
},
],
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
connection: 'close',
'content-encoding': 'gzip',
'content-security-policy': 'default-src \'none\'',
'content-type': 'application/json; charset=utf-8',
date: 'Sat, 20 May 2023 00:15:13 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: 'GitHub.com',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'transfer-encoding': 'chunked',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-media-type': 'github.v3; format=json',
'x-github-request-id': 'E53B:4AD2:8F6A462:944B6F1:64681111',
'x-ratelimit-limit': '5000',
'x-ratelimit-remaining': '4989',
'x-ratelimit-reset': '1684545298',
'x-ratelimit-resource': 'graphql',
'x-ratelimit-used': '11',
'x-xss-protection': '0',
},
request: {
query: `␊
query getProjectCoreData($owner: String!, $number: Int!) {␊
userOrOrganization: repositoryOwner(login: $owner) {␊
... on ProjectV2Owner {␊
projectV2(number: $number) {␊
id␊
title␊
url␊
databaseId␊
fields(first: 50) {␊
nodes {␊
... on ProjectV2FieldCommon {␊
id␊
dataType␊
name␊
}␊
... on ProjectV2SingleSelectField {␊
options {␊
id␊
name␊
}␊
}␊
... on ProjectV2IterationField {␊
configuration {␊
iterations {␊
title␊
duration␊
startDate␊
}␊
completedIterations {␊
title␊
duration␊
startDate␊
}␊
duration␊
startDay␊
}␊
}␊
}␊
}␊
}␊
}␊
}␊
}␊
`,
variables: {
{
error: GitHubProjectNotFoundError {
details: {
number: 99999,
owner: 'github-project-fixtures',
},
message: 'Project cannot be found',
},
response: {
data: {
userOrOrganization: {
projectV2: null,
},
},
errors: [
{
locations: [
{
column: 9,
line: 5,
},
],
message: 'Could not resolve to a ProjectV2 with the number 99999.',
path: [
'userOrOrganization',
'projectV2',
],
type: 'NOT_FOUND',
},
],
},
message: `Request failed due to following response errors:␊
- Could not resolve to a ProjectV2 with the number 99999.`,
humanMessage: 'Project #99999 could not be found for @github-project-fixtures',
}

## api.items.add
Expand Down Expand Up @@ -7416,128 +7301,13 @@ Generated by [AVA](https://avajs.dev).

> Snapshot 1
GraphqlResponseError {
data: {
userOrOrganization: {
projectV2: null,
},
},
errors: [
{
locations: [
{
column: 9,
line: 5,
},
],
message: 'Could not resolve to a ProjectV2 with the number 99999.',
path: [
'userOrOrganization',
'projectV2',
],
type: 'NOT_FOUND',
},
],
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
connection: 'close',
'content-encoding': 'gzip',
'content-security-policy': 'default-src \'none\'',
'content-type': 'application/json; charset=utf-8',
date: 'Sat, 20 May 2023 00:26:01 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: 'GitHub.com',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'transfer-encoding': 'chunked',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-media-type': 'github.v3; format=json',
'x-github-request-id': 'E839:7581:96367AB:9ADE7CC:64681399',
'x-ratelimit-limit': '5000',
'x-ratelimit-remaining': '4496',
'x-ratelimit-reset': '1684545298',
'x-ratelimit-resource': 'graphql',
'x-ratelimit-used': '504',
'x-xss-protection': '0',
},
request: {
query: `␊
query getProjectCoreData($owner: String!, $number: Int!) {␊
userOrOrganization: repositoryOwner(login: $owner) {␊
... on ProjectV2Owner {␊
projectV2(number: $number) {␊
id␊
title␊
url␊
databaseId␊
fields(first: 50) {␊
nodes {␊
... on ProjectV2FieldCommon {␊
id␊
dataType␊
name␊
}␊
... on ProjectV2SingleSelectField {␊
options {␊
id␊
name␊
}␊
}␊
... on ProjectV2IterationField {␊
configuration {␊
iterations {␊
title␊
duration␊
startDate␊
}␊
completedIterations {␊
title␊
duration␊
startDate␊
}␊
duration␊
startDay␊
}␊
}␊
}␊
}␊
}␊
}␊
}␊
}␊
`,
variables: {
{
error: GitHubProjectNotFoundError {
details: {
number: 99999,
owner: 'github-project-fixtures',
},
message: 'Project cannot be found',
},
response: {
data: {
userOrOrganization: {
projectV2: null,
},
},
errors: [
{
locations: [
{
column: 9,
line: 5,
},
],
message: 'Could not resolve to a ProjectV2 with the number 99999.',
path: [
'userOrOrganization',
'projectV2',
],
type: 'NOT_FOUND',
},
],
},
message: `Request failed due to following response errors:␊
- Could not resolve to a ProjectV2 with the number 99999.`,
humanMessage: 'Project #99999 could not be found for @github-project-fixtures',
}
Binary file modified test/snapshots/recorded.test.js.snap
Binary file not shown.

0 comments on commit 2dfdf7e

Please sign in to comment.