Skip to content

Commit 1fdf39f

Browse files
Merge branch 'develop' into feature/change-nickname
2 parents e795c01 + 4454363 commit 1fdf39f

File tree

7 files changed

+77
-2
lines changed

7 files changed

+77
-2
lines changed

.github/workflows/register-commands-production.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
jobs:
66
Register-Commands:
77
runs-on: ubuntu-latest
8-
environment: staging
8+
environment: production
99
steps:
1010
- uses: actions/checkout@v2
1111
- run: npm install
@@ -28,7 +28,9 @@ jobs:
2828
DISCORD_PUBLIC_KEY
2929
DISCORD_TOKEN
3030
DISCORD_GUILD_ID
31+
CURRENT_ENVIRONMENT
3132
env:
33+
CURRENT_ENVIRONMENT: production
3234
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
3335
DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}}
3436
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}

.github/workflows/register-commands-staging.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ jobs:
2828
DISCORD_PUBLIC_KEY
2929
DISCORD_TOKEN
3030
DISCORD_GUILD_ID
31+
CURRENT_ENVIRONMENT
3132
env:
33+
CURRENT_ENVIRONMENT: staging
3234
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
3335
DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}}
3436
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}

config/config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { env, environment } 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: environment = {
10+
production: {
11+
RDS_BASE_API_URL: RDS_BASE_API_URL,
12+
},
13+
staging: {
14+
RDS_BASE_API_URL: RDS_BASE_STAGING_API_URL,
15+
},
16+
default: {
17+
RDS_BASE_API_URL: RDS_BASE_DEVELOPMENT_API_URL,
18+
},
19+
};
20+
21+
return environment[env.CURRENT_ENVIRONMENT] || environment.default;
22+
};
23+
24+
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";

src/typeDefinitions/default.types.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ export interface env {
22
[key: string]: string;
33
}
44

5+
export interface environment {
6+
[key: string]: variables;
7+
}
8+
9+
export interface variables {
10+
RDS_BASE_API_URL: string;
11+
}
12+
513
export interface discordCommand {
614
name: string;
715
description: string;

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)