Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"esbuild": "^0.24.0",
"fetch-mock": "^11.0.0",
"fetch-mock": "^12.0.0",
"glob": "^11.0.0",
"jest": "^29.0.0",
"prettier": "3.3.3",
Expand Down
62 changes: 34 additions & 28 deletions test/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ describe("graphql.defaults()", () => {
},
};

const mock = fetchMock.createInstance().post(
"https://api.github.com/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
);

const authenticatedGraphql = graphql.defaults({
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://api.github.com/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
),
fetch: mock.fetchHandler,
},
});
return authenticatedGraphql(`{
Expand Down Expand Up @@ -92,20 +94,22 @@ describe("graphql.defaults()", () => {
},
};

const mock = fetchMock.createInstance().post(
"https://github.acme-inc.com/api/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
);

const authenticatedGraphql = graphql.defaults({
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://github.acme-inc.com/api/graphql",
{ data: mockData },
{
headers: {
authorization: "token secret123",
},
},
),
fetch: mock.fetchHandler,
},
});
const acmeGraphql = authenticatedGraphql.defaults({
Expand All @@ -127,21 +131,23 @@ describe("graphql.defaults()", () => {
});

it("handle baseUrl set with /api/v3 suffix", () => {
const mock = fetchMock.createInstance().post(
"https://github.acme-inc.com/api/graphql",
{ data: { ok: true } },
{
headers: {
authorization: "token secret123",
},
},
);

const ghesGraphQl = graphql.defaults({
baseUrl: "https://github.acme-inc.com/api/v3",
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://github.acme-inc.com/api/graphql",
{ data: { ok: true } },
{
headers: {
authorization: "token secret123",
},
},
),
fetch: mock.fetchHandler,
},
});

Expand Down Expand Up @@ -182,7 +188,7 @@ describe("graphql.defaults()", () => {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
fetch: fetchMock.createInstance().post(
"https://github.acme-inc.com/api/graphql",
{ data: mockData },
{
Expand Down
38 changes: 25 additions & 13 deletions test/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ describe("errors", () => {
],
};

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", mockResponse);

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock
.sandbox()
.post("https://api.github.com/graphql", mockResponse),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down Expand Up @@ -72,14 +74,16 @@ describe("errors", () => {
],
};

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", mockResponse);

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock
.sandbox()
.post("https://api.github.com/graphql", mockResponse),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down Expand Up @@ -131,17 +135,21 @@ describe("errors", () => {
],
};

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", {
body: mockResponse,
headers: {
"x-github-request-id": "C5E6:259A:1351B40:2E88B87:5F1F9C41",
},
});

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post("https://api.github.com/graphql", {
body: mockResponse,
headers: {
"x-github-request-id": "C5E6:259A:1351B40:2E88B87:5F1F9C41",
},
}),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down Expand Up @@ -173,12 +181,16 @@ describe("errors", () => {
}
}`;

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", 500);

return graphql(query, {
headers: {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post("https://api.github.com/graphql", 500),
fetch: mock.fetchHandler,
},
})
.then(() => {
Expand Down
Loading