Skip to content

Commit

Permalink
test: switch from toStrictEqual to toMatchObject
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Jun 17, 2023
1 parent 009ef0e commit b672135
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 101 deletions.
49 changes: 24 additions & 25 deletions test/node-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createServer, IncomingMessage } from "http";
import { URL } from "url";

import fetch from "node-fetch";
import { createNodeMiddleware, OAuthApp } from "../src/";

// import without types
Expand Down Expand Up @@ -151,7 +150,7 @@ describe("createNodeMiddleware(app)", () => {
expect(await response.text()).toMatch(/token123/);

expect(appMock.createToken.mock.calls.length).toEqual(1);
expect(appMock.createToken.mock.calls[0][0]).toStrictEqual({
expect(appMock.createToken.mock.calls[0][0]).toMatchObject({
code: "012345",
});
});
Expand Down Expand Up @@ -187,12 +186,12 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(201);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
authentication: { type: "token", tokenType: "oauth" },
});

expect(appMock.createToken.mock.calls.length).toEqual(1);
expect(appMock.createToken.mock.calls[0][0]).toStrictEqual({
expect(appMock.createToken.mock.calls[0][0]).toMatchObject({
code: "012345",
redirectUrl: "http://example.com",
});
Expand Down Expand Up @@ -228,13 +227,13 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(200);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
data: { id: 1 },
authentication: { type: "token", tokenType: "oauth" },
});

expect(appMock.checkToken.mock.calls.length).toEqual(1);
expect(appMock.checkToken.mock.calls[0][0]).toStrictEqual({
expect(appMock.checkToken.mock.calls[0][0]).toMatchObject({
token: "token123",
});
});
Expand Down Expand Up @@ -270,13 +269,13 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(200);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
data: { id: 1 },
authentication: { type: "token", tokenType: "oauth" },
});

expect(appMock.resetToken.mock.calls.length).toEqual(1);
expect(appMock.resetToken.mock.calls[0][0]).toStrictEqual({
expect(appMock.resetToken.mock.calls[0][0]).toMatchObject({
token: "token123",
});
});
Expand Down Expand Up @@ -377,14 +376,14 @@ describe("createNodeMiddleware(app)", () => {

server.close();

expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
data: { id: 1 },
authentication: { type: "token", tokenType: "oauth" },
});
expect(response.status).toEqual(200);

expect(appMock.refreshToken.mock.calls.length).toEqual(1);
expect(appMock.refreshToken.mock.calls[0][0]).toStrictEqual({
expect(appMock.refreshToken.mock.calls[0][0]).toMatchObject({
refreshToken: "r1.refreshtoken123",
});
});
Expand Down Expand Up @@ -419,13 +418,13 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(200);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
data: { id: 1 },
authentication: { type: "token", tokenType: "oauth" },
});

expect(appMock.resetToken.mock.calls.length).toEqual(1);
expect(appMock.resetToken.mock.calls[0][0]).toStrictEqual({
expect(appMock.resetToken.mock.calls[0][0]).toMatchObject({
token: "token123",
});
});
Expand Down Expand Up @@ -456,7 +455,7 @@ describe("createNodeMiddleware(app)", () => {
expect(response.status).toEqual(204);

expect(appMock.deleteToken.mock.calls.length).toEqual(1);
expect(appMock.deleteToken.mock.calls[0][0]).toStrictEqual({
expect(appMock.deleteToken.mock.calls[0][0]).toMatchObject({
token: "token123",
});
});
Expand Down Expand Up @@ -487,7 +486,7 @@ describe("createNodeMiddleware(app)", () => {
expect(response.status).toEqual(204);

expect(appMock.deleteAuthorization.mock.calls.length).toEqual(1);
expect(appMock.deleteAuthorization.mock.calls[0][0]).toStrictEqual({
expect(appMock.deleteAuthorization.mock.calls[0][0]).toMatchObject({
token: "token123",
});
});
Expand Down Expand Up @@ -530,7 +529,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "code" parameter is required',
});
});
Expand All @@ -551,7 +550,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error:
"[@octokit/oauth-app] redirect_uri_mismatch The redirect_uri MUST match the registered callback URL for this application.",
});
Expand All @@ -577,7 +576,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "code" parameter is required',
});
});
Expand All @@ -602,7 +601,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: "[@octokit/oauth-app] request error",
});
});
Expand All @@ -626,7 +625,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "Authorization" header is required',
});
});
Expand All @@ -651,7 +650,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "Authorization" header is required',
});
});
Expand All @@ -676,7 +675,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "Authorization" header is required',
});
});
Expand Down Expand Up @@ -707,7 +706,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "Authorization" header is required',
});
});
Expand Down Expand Up @@ -738,7 +737,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: "[@octokit/oauth-app] refreshToken must be sent in request body",
});
});
Expand All @@ -763,7 +762,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "Authorization" header is required',
});
});
Expand All @@ -788,7 +787,7 @@ describe("createNodeMiddleware(app)", () => {
server.close();

expect(response.status).toEqual(400);
expect(await response.json()).toStrictEqual({
expect(await response.json()).toMatchObject({
error: '[@octokit/oauth-app] "Authorization" header is required',
});
});
Expand Down
Loading

0 comments on commit b672135

Please sign in to comment.