Skip to content

Commit 940e2a0

Browse files
committed
environment setup
1 parent 7253b49 commit 940e2a0

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

config/config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { env } from "../src/typeDefinitions/default.types";
2+
import {
3+
RDS_BASE_API_URL,
4+
RDS_BASE_STAGING_API_URL,
5+
RDS_BASE_DEVELOPMENT_API_URL,
6+
} from "../src/constants/urls";
7+
8+
const config = (env: env) => {
9+
const environment = { RDS_BASE_API_URL: "" };
10+
11+
switch (env.CURRENT_ENVIRONMENT) {
12+
case "production":
13+
environment.RDS_BASE_API_URL = RDS_BASE_API_URL;
14+
break;
15+
16+
case "staging":
17+
environment.RDS_BASE_API_URL = RDS_BASE_STAGING_API_URL;
18+
break;
19+
20+
default:
21+
environment.RDS_BASE_API_URL = RDS_BASE_DEVELOPMENT_API_URL;
22+
}
23+
24+
return environment;
25+
};
26+
27+
export default config;

src/constants/urls.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export const RDS_API_BASE_URL = "https://api.realdevsquad.com";
1+
export const RDS_BASE_API_URL = "https://api.realdevsquad.com";
2+
export const RDS_BASE_STAGING_API_URL = "https://staging-api.realdevsquad.com";
3+
export const RDS_BASE_DEVELOPMENT_API_URL = "http://localhost:3000"; // If needed, modify the URL to your local API server
4+
25
export const DISCORD_BASE_URL = "https://discord.com/api/v10";
36
export const VERIFICATION_SITE_URL = "https://my.realdevsquad.com";

tests/fixtures/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const environment = [
2+
{
3+
CURRENT_ENVIRONMENT: "production",
4+
},
5+
{
6+
CURRENT_ENVIRONMENT: "staging",
7+
},
8+
{
9+
CURRENT_ENVIRONMENT: "",
10+
},
11+
];

tests/unit/config/config.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import config from "../../../config/config";
2+
import { environment } from "../../fixtures/config";
3+
import {
4+
RDS_BASE_API_URL,
5+
RDS_BASE_DEVELOPMENT_API_URL,
6+
RDS_BASE_STAGING_API_URL,
7+
} from "../../../src/constants/urls";
8+
9+
describe("Test config function", () => {
10+
it("Should return production config environment", () => {
11+
expect(config(environment[0]).RDS_BASE_API_URL).toBe(RDS_BASE_API_URL);
12+
});
13+
14+
it("Should return staging config environment", () => {
15+
expect(config(environment[1]).RDS_BASE_API_URL).toBe(
16+
RDS_BASE_STAGING_API_URL
17+
);
18+
});
19+
20+
it("Should return default config environment", () => {
21+
expect(config(environment[2]).RDS_BASE_API_URL).toBe(
22+
RDS_BASE_DEVELOPMENT_API_URL
23+
);
24+
});
25+
});

0 commit comments

Comments
 (0)