Skip to content

Commit

Permalink
error handling and ENV setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sadabnepal committed Jun 25, 2024
1 parent ae2a4f6 commit 852ea41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
GO_RES_USER_TOKEN=
GO_RES_USER_TOKEN=
ENV=
1 change: 1 addition & 0 deletions tests/env/manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { config } from 'dotenv';
import { join } from 'path';
config();

const environment = process.env.ENV;
if (!environment) throw new Error('please pass the environment variable. Options: | dev | stage | prod |');
Expand Down
30 changes: 20 additions & 10 deletions tests/helper/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import { ENV } from 'env/manager';
import supertest from 'supertest';

export const queryGraphQl = async (token: string, graphQLQuery: string) => {
const response = await supertest(ENV.BASEURL)
.post(ENV.ENDPOINT)
.set({ 'authorization': `Bearer ${token}` })
.send({ query: graphQLQuery });
return response;
try {
const response = await supertest(ENV.BASEURL)
.post(ENV.ENDPOINT)
.set({ 'authorization': `Bearer ${token}` })
.send({ query: graphQLQuery });
return response;
} catch (error) {
console.error(`Error making request to ${ENV.BASEURL + ENV.ENDPOINT}:`, error);
throw error;
}
};

export const mutateGraphQl = async (token: string, mutationPayload: string) => {
const response = await supertest(ENV.BASEURL)
.post(ENV.ENDPOINT)
.set({ 'authorization': `Bearer ${token}` })
.send({ query: mutationPayload });
return response;
try {
const response = await supertest(ENV.BASEURL)
.post(ENV.ENDPOINT)
.set({ 'authorization': `Bearer ${token}` })
.send({ query: mutationPayload });
return response;
} catch (error) {
console.error(`Error making request to ${ENV.BASEURL + ENV.ENDPOINT}:`, error);
throw error;
}
};

0 comments on commit 852ea41

Please sign in to comment.