diff --git a/index.test-d.ts b/index.test-d.ts index 50978e53..305d2e3b 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -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() { @@ -309,7 +311,7 @@ export async function getItemByRepositoryAndNumberTest() { }); const item = await project.items.getByContentRepositoryAndNumber( "repository-name", - 1, + 1 ); if (typeof item === "undefined") { @@ -460,7 +462,7 @@ export async function updateItemByContentRepositoryAndNumberTest() { 1, { status: "new status", - }, + } ); if (typeof item === "undefined") { @@ -539,7 +541,7 @@ export async function archiveItemByContentRepositoryAndNameTest() { }); const item = await project.items.archiveByContentRepositoryAndNumber( "repository-name", - 1, + 1 ); if (typeof item === "undefined") { @@ -590,7 +592,7 @@ export async function removeItemByContentRepositoryAndNameTest() { }); const item = await project.items.removeByContentRepositoryAndNumber( "repository-name", - 1, + 1 ); if (typeof item === "undefined") { @@ -655,6 +657,18 @@ export function testGitHubProjectError() { expectType(error.toHumanMessage()); } +export function testGitHubProjectNotFoundError() { + const details = { + owner: "owner", + number: 1, + }; + const error = new GitHubProjectNotFoundError(details); + + expectType<"GitHubProjectNotFoundError">(error.name); + expectType(error.details); + expectType(error.toHumanMessage()); +} + export function testGitHubProjectUnknownFieldError() { const details = { projectFieldNames: ["one", "two"], @@ -688,3 +702,21 @@ export function testGitHubProjectUnknownFieldOptionError() { expectType(error.details); expectType(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(error.details); + expectType(error.toHumanMessage()); +} diff --git a/test/snapshots/recorded.test.js.md b/test/snapshots/recorded.test.js.md index b45de11e..10a2c484 100644 --- a/test/snapshots/recorded.test.js.md +++ b/test/snapshots/recorded.test.js.md @@ -49,130 +49,12 @@ 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: { - number: 99999, - owner: 'github-project-fixtures', - }, - }, - 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', - }, - ], + GitHubProjectNotFoundError { + details: { + number: 99999, + owner: 'github-project-fixtures', }, - message: `Request failed due to following response errors:␊ - - Could not resolve to a ProjectV2 with the number 99999.`, + message: 'Project cannot be found', } ## api.items.add @@ -7416,128 +7298,10 @@ 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: { - number: 99999, - owner: 'github-project-fixtures', - }, - }, - 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', - }, - ], + GitHubProjectNotFoundError { + details: { + number: 99999, + owner: 'github-project-fixtures', }, - message: `Request failed due to following response errors:␊ - - Could not resolve to a ProjectV2 with the number 99999.`, + message: 'Project cannot be found', } diff --git a/test/snapshots/recorded.test.js.snap b/test/snapshots/recorded.test.js.snap index 8bb56811..2b864694 100644 Binary files a/test/snapshots/recorded.test.js.snap and b/test/snapshots/recorded.test.js.snap differ