Skip to content

Commit

Permalink
import path enhance using tsconfig-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
sadabnepal committed May 26, 2024
1 parent 2f5e246 commit 495ad68
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: npm ci

- name: Run lint and test
run: npm run lint&&export GO_RES_USER_TOKEN=${{ secrets.API_TOKEN }}&&npm test
run: npm run lint&&export GO_RES_USER_TOKEN=${{ secrets.API_TOKEN }}&&export ENV=dev&&npm test

- name: Create Report
uses: phoenix-actions/test-reporting@v8
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
'showSkipped=true',
'showHooks=failed'
],
require: ['ts-node/register'],
require: ['ts-node/register', 'tsconfig-paths/register'],
parallel: false,
recursive: false,
retries: 0,
Expand Down
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"mochawesome": "^7.1.3",
"supertest": "^6.3.4",
"ts-node": "^10.7.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^4.6.4",
"typescript-eslint": "^7.8.0"
},
"engines": {
"node": ">=16.0.0 <20.0.0"
}
}
}
2 changes: 1 addition & 1 deletion tests/data/faker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faker } from '@faker-js/faker';
import { IUser, IUserOmittedID } from '../types/users';
import { IUser, IUserOmittedID } from 'types/users';

export const createUserData: IUserOmittedID = {
name: faker.person.fullName(),
Expand Down
9 changes: 5 additions & 4 deletions tests/helper/apiUtils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ENV } from 'env/manager';
import supertest from 'supertest';

export const queryGraphQl = async (token: string, graphQLQuery: string) => {
const response = await supertest('https://gorest.co.in/public')
.post('/v2/graphql')
const response = await supertest(ENV.BASEURL)
.post(ENV.ENDPOINT)
.set({ 'authorization': `Bearer ${token}` })
.send({ query: graphQLQuery });
return response;
};

export const mutateGraphQl = async (token: string, mutationPayload: string) => {
const response = await supertest('https://gorest.co.in/public')
.post('/v2/graphql')
const response = await supertest(ENV.BASEURL)
.post(ENV.ENDPOINT)
.set({ 'authorization': `Bearer ${token}` })
.send({ query: mutationPayload });
return response;
Expand Down
2 changes: 1 addition & 1 deletion tests/payload/directives.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { userResponseFields } from './fragments';

export const queryUsersWithNodeDirectivePayload = (includeNodes = true) => {
export const queryUsers = (includeNodes: boolean) => {
return `{
users {
totalCount
Expand Down
2 changes: 1 addition & 1 deletion tests/payload/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IUser, IUserOmittedID } from '../types/users';
import { IUser, IUserOmittedID } from 'types/users';
import { userFragments, userResponseFields } from './fragments';

export const createUserPayload = (data: IUserOmittedID) => {
Expand Down
16 changes: 8 additions & 8 deletions tests/specs/goRestTests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from 'chai';
import { createUserData, updateUserData } from 'data/faker';
import { config } from 'dotenv';
import { createUserData, updateUserData } from '../data/faker';
import { mutateGraphQl, queryGraphQl } from '../helper/apiUtils';
import { queryUsersWithNodeDirectivePayload } from '../payload/directives';
import { createUserPayload, deleteUserPayload, updateUserPayload } from '../payload/mutation';
import { queryAllUserPayload, queryUserByIdPayload } from '../payload/queries';
import { INonExistingUserError, IUser, IUserCreate, IUserDelete, IUserUpdate, IUsers } from '../types/users';
import { mutateGraphQl, queryGraphQl } from 'helper/apiUtils';
import { queryUsers } from 'payload/directives';
import { createUserPayload, deleteUserPayload, updateUserPayload } from 'payload/mutation';
import { queryAllUserPayload, queryUserByIdPayload } from 'payload/queries';
import { INonExistingUserError, IUser, IUserCreate, IUserDelete, IUserUpdate, IUsers } from 'types/users';
config();

const TOKEN = process.env.GO_RES_USER_TOKEN;
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('go rest graphql tests', () => {
});

it('should query user count only using directives', async () => {
const response = await queryGraphQl(TOKEN, queryUsersWithNodeDirectivePayload(false));
const response = await queryGraphQl(TOKEN, queryUsers(false));
expect(response.statusCode).equal(200);

const responseData: IUsers = response.body.data;
Expand All @@ -145,7 +145,7 @@ describe('go rest graphql tests', () => {
});

it('should query user with all nodes using directives', async () => {
const response = await queryGraphQl(TOKEN, queryUsersWithNodeDirectivePayload(true));
const response = await queryGraphQl(TOKEN, queryUsers(true));
expect(response.statusCode).equal(200);

const responseData: IUsers = response.body.data;
Expand Down
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"esModuleInterop": true,
"resolveJsonModule": true,
"baseUrl": "./tests"
// "allowSyntheticDefaultImports": true,
// "forceConsistentCasingInFileNames": true,
// "strict": true,
Expand All @@ -19,6 +20,10 @@
// "noImplicitOverride": true,
// "skipLibCheck": true
},
"include": ["tests/**/*.ts"],
"exclude": ["node_modules"]
"include": [
"tests/**/*.ts"
],
"exclude": [
"node_modules"
]
}

0 comments on commit 495ad68

Please sign in to comment.