-
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.
refactor: Update buildConfig to use environment variables for configu…
…ration
- Loading branch information
1 parent
6a1429c
commit bd36282
Showing
3 changed files
with
59 additions
and
54 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const buildConfig = () => ({ | ||
server_port: process.env.PORT || 4000, | ||
api_url: process.env.API_URL || "http://localhost:5000", | ||
client_url: process.env.CLIENT_URL || "http://localhost:5173", | ||
server_url: process.env.SERVER_URL || "http://localhost:4000", | ||
redis_url: process.env.REDIS_URL || "redis://localhost:6379", | ||
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, | ||
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET, | ||
SESSION_SECRET: process.env.SESSION_SECRET, | ||
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID, | ||
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET, | ||
}); |
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 |
---|---|---|
@@ -1,57 +1,60 @@ | ||
import request from 'supertest'; | ||
import Agent from'supertest'; | ||
import request from "supertest"; | ||
import Agent from "supertest"; | ||
import express from "express"; | ||
import axios from 'axios'; | ||
import passport from 'passport'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { router } from '../../src/routes/routes'; | ||
import { configureApp } from '../../src/configureApp'; | ||
import versionInfo from '../../../server/resources/versionInfo.json'; | ||
import config from '../../src/resources/config.json'; | ||
import MockStrategy from 'passport-mock-strategy'; | ||
import axios from "axios"; | ||
import passport from "passport"; | ||
import MockAdapter from "axios-mock-adapter"; | ||
import { router } from "../../src/routes/routes"; | ||
import { configureApp } from "../../src/configureApp"; | ||
import versionInfo from "../../../server/resources/versionInfo.json"; | ||
import MockStrategy from "passport-mock-strategy"; | ||
import dotenv from "dotenv"; | ||
import { buildConfig } from "../../src/buildConfig"; | ||
|
||
dotenv.config({ path: ".env.development" }); | ||
const config = buildConfig(); | ||
const app = express(); | ||
configureApp(app, config); | ||
router(app, config) | ||
router(app, config); | ||
|
||
// adding passport mock strategy and route for tests | ||
passport.use(new MockStrategy()); | ||
app.get('/login/mock', passport.authenticate('mock'), (req, res) => { | ||
res.send({ status: 'ok' }); | ||
}); | ||
app.get("/login/mock", passport.authenticate("mock"), (req, res) => { | ||
res.send({ status: "ok" }); | ||
}); | ||
|
||
describe("testing-server-routes", () => { | ||
const mock = new MockAdapter(axios); | ||
mock.onGet(`${config.api_url}/version`).reply(200, versionInfo); | ||
const mock = new MockAdapter(axios); | ||
mock.onGet(`${config.api_url}/version`).reply(200, versionInfo); | ||
|
||
it("GET /version", async () => { | ||
const response= await request(app).get("/version"); | ||
expect(response.body).toMatchObject(versionInfo); | ||
}); | ||
it("GET /", async () => { | ||
const { body } = await request(app).get("/"); | ||
expect(body).toEqual({ message: 'Welcome to beebop!' }); | ||
}); | ||
it("GET /user", async () => { | ||
const { body } = await request(app).get("/user"); | ||
expect(body.status).toEqual('failure'); | ||
}); | ||
it("GET /version", async () => { | ||
const response = await request(app).get("/version"); | ||
expect(response.body).toMatchObject(versionInfo); | ||
}); | ||
it("GET /", async () => { | ||
const { body } = await request(app).get("/"); | ||
expect(body).toEqual({ message: "Welcome to beebop!" }); | ||
}); | ||
it("GET /user", async () => { | ||
const { body } = await request(app).get("/user"); | ||
expect(body.status).toEqual("failure"); | ||
}); | ||
}); | ||
|
||
describe("testing-server-routes as logged in user", () => { | ||
let agent; | ||
beforeEach(() => { | ||
agent = Agent.agent(app); | ||
}); | ||
let agent; | ||
beforeEach(() => { | ||
agent = Agent.agent(app); | ||
}); | ||
|
||
it('should authenticate the user', () => { | ||
return agent.get('/login/mock').expect(200, { status: 'ok' }); | ||
}); | ||
it("should authenticate the user", () => { | ||
return agent.get("/login/mock").expect(200, { status: "ok" }); | ||
}); | ||
|
||
it("GET /user", async () => { | ||
Agent.agent | ||
await agent.get('/login/mock'); | ||
const { body } = await agent.get("/user"); | ||
expect(body.data).toEqual({id:'1234', provider:'mock', name:'Foo'}); | ||
}); | ||
}); | ||
it("GET /user", async () => { | ||
Agent.agent; | ||
await agent.get("/login/mock"); | ||
const { body } = await agent.get("/user"); | ||
expect(body.data).toEqual({ id: "1234", provider: "mock", name: "Foo" }); | ||
}); | ||
}); |