Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NOC-1903): Unit testing and API testing with jest + supertest #7

Merged
merged 16 commits into from
Mar 21, 2024

Conversation

dynamite-bud
Copy link
Collaborator

@dynamite-bud dynamite-bud commented Mar 20, 2024

Description

This PR introduces unit tests and API tests for this project.

Technologies used

I've used:

  1. jest for unit tests
  2. supertest for API testing

Test Structure

The tests live under the server/__tests__/*.

Unit tests

Unit tests are located under server/__tests__/unit/*. They currently test splitters.

  1. intercom.tests.ts
  2. json.tests.ts
  3. markdown.tests.ts
  4. pdf.tests.ts
  5. unstructured.tests.ts

These tests test the splitters' functionality to split different types of documents supplied.

API tests

These tests are located under server/__tests__/api/*. They test different endpoints such as:

1./completions
2. /pricing/model
3. /pricing/model/cost
4. /state

Tests development

Important

Please update values in your .env file following .env/example file.

Unit tests

  1. Create another file in server/__tests__/unit/
  2. Run yarn run test:unit:watch, to watch development in realtime

API tests

  1. Place one in server/__tests__/api/api.tests.ts
  2. Run API tests using yarn run test:api

Note

All API tests are written in one file and there's no watch mode as supertests instantiate an express app and as a new server is spun so if you make multiple files, multiple apps are instantiated creating the error.

ERROR: Address already in use

Running tests

Unit tests

yarn run test:unit

API tests

yarn run test:api

@ciaranjmp ciaranjmp changed the title Feat: Unit testing and API testing with jest + supertest feat(NOC-1903): Unit testing and API testing with jest + supertest Mar 20, 2024
@dynamite-bud dynamite-bud requested a review from ciaranjmp March 21, 2024 10:03
@ciaranjmp ciaranjmp marked this pull request as ready for review March 21, 2024 13:47
Copy link
Collaborator

@ciaranjmp ciaranjmp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @dynamite-bud! I've made some minor changes and we're now ready to merge 💪

@ciaranjmp
Copy link
Collaborator

Note, all tests can now be run with yarn run test and you can use yarn run test:debug to get logs. You can also run make test to run the testing suite.

The required node version has also been bumped to v20 because node version 19.8.1 is not compatible with ts-jest.

@dynamite-bud dynamite-bud merged commit 3529f03 into main Mar 21, 2024
1 check passed
@dmmc12 dmmc12 deleted the testing-with-jest branch March 21, 2024 16:43
dynamite-bud added a commit that referenced this pull request Mar 22, 2024
feat(NOC-1903): Unit testing and API testing with jest + supertest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants