diff --git a/.env.example b/.env.example index e2a73c5..d0742b2 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -GO_RES_USER_TOKEN= \ No newline at end of file +GO_RES_USER_TOKEN= +ENV= \ No newline at end of file diff --git a/tests/env/manager.ts b/tests/env/manager.ts index 11918be..fcf72bc 100644 --- a/tests/env/manager.ts +++ b/tests/env/manager.ts @@ -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 |'); diff --git a/tests/helper/apiUtils.ts b/tests/helper/apiUtils.ts index d63526c..15428f0 100644 --- a/tests/helper/apiUtils.ts +++ b/tests/helper/apiUtils.ts @@ -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; + } }; \ No newline at end of file