Skip to content

Commit 852ea41

Browse files
committed
error handling and ENV setup
1 parent ae2a4f6 commit 852ea41

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
GO_RES_USER_TOKEN=
1+
GO_RES_USER_TOKEN=
2+
ENV=

tests/env/manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { config } from 'dotenv';
22
import { join } from 'path';
3+
config();
34

45
const environment = process.env.ENV;
56
if (!environment) throw new Error('please pass the environment variable. Options: | dev | stage | prod |');

tests/helper/apiUtils.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@ import { ENV } from 'env/manager';
22
import supertest from 'supertest';
33

44
export const queryGraphQl = async (token: string, graphQLQuery: string) => {
5-
const response = await supertest(ENV.BASEURL)
6-
.post(ENV.ENDPOINT)
7-
.set({ 'authorization': `Bearer ${token}` })
8-
.send({ query: graphQLQuery });
9-
return response;
5+
try {
6+
const response = await supertest(ENV.BASEURL)
7+
.post(ENV.ENDPOINT)
8+
.set({ 'authorization': `Bearer ${token}` })
9+
.send({ query: graphQLQuery });
10+
return response;
11+
} catch (error) {
12+
console.error(`Error making request to ${ENV.BASEURL + ENV.ENDPOINT}:`, error);
13+
throw error;
14+
}
1015
};
1116

1217
export const mutateGraphQl = async (token: string, mutationPayload: string) => {
13-
const response = await supertest(ENV.BASEURL)
14-
.post(ENV.ENDPOINT)
15-
.set({ 'authorization': `Bearer ${token}` })
16-
.send({ query: mutationPayload });
17-
return response;
18+
try {
19+
const response = await supertest(ENV.BASEURL)
20+
.post(ENV.ENDPOINT)
21+
.set({ 'authorization': `Bearer ${token}` })
22+
.send({ query: mutationPayload });
23+
return response;
24+
} catch (error) {
25+
console.error(`Error making request to ${ENV.BASEURL + ENV.ENDPOINT}:`, error);
26+
throw error;
27+
}
1828
};

0 commit comments

Comments
 (0)