-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from sametcodes/develop
Passport.js, supports Public APIs and unit tests
- Loading branch information
Showing
47 changed files
with
8,334 additions
and
7,701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
npx lint-staged | ||
npm run lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { testApiHandler } from "next-test-api-route-handler"; | ||
import handlePlatformAPI from "@/services/api/handler"; | ||
|
||
import { encode } from "querystring"; | ||
|
||
import * as services from "@/services/platform/codewars"; | ||
import * as templates from "@/components/svgs/codewars"; | ||
|
||
const handler = handlePlatformAPI("codewars", services, templates); | ||
const methods = Object.keys(services); | ||
|
||
describe("Codewars Platform APIs", () => { | ||
methods.forEach((method) => { | ||
test(`/api/platform/codewars?method=${method}`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/codewars?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.status).toBe(200); | ||
|
||
const xml = await res.text(); | ||
expect(xml.indexOf("<svg")).toBe(0); | ||
}, | ||
}); | ||
}); | ||
|
||
test(`/api/platform/codewars?method=${method}&returnType=json`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/codewars?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
returnType: "json", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.headers.get("content-type")).toContain("application/json"); | ||
expect(res.status).toBe(200); | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { testApiHandler } from "next-test-api-route-handler"; | ||
import handlePlatformAPI from "@/services/api/handler"; | ||
|
||
import { encode } from "querystring"; | ||
|
||
import * as services from "@/services/platform/github"; | ||
import * as templates from "@/components/svgs/github"; | ||
|
||
const handler = handlePlatformAPI("github", services, templates); | ||
const methods = Object.keys(services); | ||
|
||
describe("Github Platform APIs", () => { | ||
methods.forEach((method) => { | ||
test(`/api/platform/github?method=${method}`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/github?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.status).toBe(200); | ||
|
||
const xml = await res.text(); | ||
expect(xml.indexOf("<svg")).toBe(0); | ||
}, | ||
}); | ||
}); | ||
|
||
test(`/api/platform/github?method=${method}&returnType=json`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/github?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
returnType: "json", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.headers.get("content-type")).toContain("application/json"); | ||
expect(res.status).toBe(200); | ||
|
||
const json = await res.json(); | ||
expect(json).toHaveProperty("data"); | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { testApiHandler } from "next-test-api-route-handler"; | ||
import handlePlatformAPI from "@/services/api/handler"; | ||
|
||
import { encode } from "querystring"; | ||
|
||
import * as services from "@/services/platform/stackoverflow"; | ||
import * as templates from "@/components/svgs/stackoverflow"; | ||
|
||
const handler = handlePlatformAPI("stackoverflow", services, templates); | ||
const methods = Object.keys(services); | ||
|
||
describe("Stackoverflow Platform APIs", () => { | ||
methods.forEach((method) => { | ||
test(`/api/platform/stackoverflow?method=${method}`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/stackoverflow?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.status).toBe(200); | ||
|
||
const xml = await res.text(); | ||
expect(xml.indexOf("<svg")).toBe(0); | ||
}, | ||
}); | ||
}); | ||
|
||
test(`/api/platform/stackoverflow?method=${method}&returnType=json`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/stackoverflow?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
returnType: "json", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.headers.get("content-type")).toContain("application/json"); | ||
expect(res.status).toBe(200); | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { testApiHandler } from "next-test-api-route-handler"; | ||
import handlePlatformAPI from "@/services/api/handler"; | ||
|
||
import { encode } from "querystring"; | ||
|
||
import * as services from "@/services/platform/wakatime"; | ||
import * as templates from "@/components/svgs/wakatime"; | ||
|
||
const handler = handlePlatformAPI("wakatime", services, templates); | ||
const methods = Object.keys(services); | ||
|
||
describe("Wakatime Platform APIs", () => { | ||
methods.forEach((method) => { | ||
test(`/api/platform/wakatime?method=${method}`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/wakatime?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.status).toBe(200); | ||
|
||
const xml = await res.text(); | ||
expect(xml.indexOf("<svg")).toBe(0); | ||
}, | ||
}); | ||
}); | ||
|
||
test(`/api/platform/wakatime?method=${method}&returnType=json`, async () => { | ||
await testApiHandler({ | ||
handler, | ||
requestPatcher: (req) => { | ||
req.url = `/api/platform/wakatime?${encode({ | ||
method, | ||
uid: "6405534466df6b87ed0adb53", | ||
returnType: "json", | ||
})}`; | ||
}, | ||
test: async ({ fetch }) => { | ||
const res = await fetch({ method: "GET" }); | ||
expect(res.headers.get("content-type")).toContain("application/json"); | ||
expect(res.status).toBe(200); | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const nextJest = require("next/jest"); | ||
|
||
const createJestConfig = nextJest({ | ||
dir: "./", | ||
}); | ||
|
||
// Add any custom config to be passed to Jest | ||
const customJestConfig = { | ||
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"], | ||
moduleNameMapper: { | ||
"^@/(.*)$": "<rootDir>/$1", | ||
}, | ||
testEnvironment: "jest-environment-jsdom", | ||
}; | ||
|
||
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
module.exports = createJestConfig(customJestConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import "@testing-library/jest-dom/extend-expect"; | ||
|
||
import { TextEncoder, TextDecoder } from "util"; | ||
import fetch from "node-fetch"; | ||
|
||
global.TextEncoder = TextEncoder; | ||
global.TextDecoder = TextDecoder; | ||
global.fetch = fetch; |
Oops, something went wrong.
09bb4f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
devstats – ./
devstats-sametcodes.vercel.app
devstats-git-main-sametcodes.vercel.app
devstats-app.vercel.app