simple app will auto create template of CRUD test case and you can modify it to complete the test case.
The simplest standalone resource step (no foreignkey) workflow of prepare test as below:
- Add sample data in
stubsatbackend/test/yourResource/stub - modify sample's
_idaccordingbackend/test/yourResource/yourResource.e2e-spec.ts - modify
yourResource.e2e-spec.tsaccording your need such as autocomplete search text or add more test
- Start backend and frontend server, access your
categorypage - Try add new record, fill in sample data and save it.
- Obtain the sample json data from debug data component.
- Put content into stub:
a. edit
backend/test/category/stub/id1.create.tsb. replace json content with copied record but remainid:"00000000-0000-0000-0000-000000000001"unchange - repeat sample step
backend/test/category/stub/id1.update.ts, but you may change the data slightly like changecategoryNamefrom "Category 1" to "Category 1-updated" - Go back to frontend, add new record and fill in sample data which not pass the input validation (safe failed)
- Copy the data into stub
a. edit
backend/test/category/stub/id2.create.tsb. replace json content with copied record but remainid:"00000000-0000-0000-0000-000000000002"unchange - After added 3 sample data into stub, you may modify
backend/test/category/category.e2e-spec.ts: a. changeexistAutoCompleteKeywordto match partial of your sample data. Example your valuecategoryNameisCategory 1, you can define asexistAutoCompleteKeyword='Cat'(It only searchcategoryCodeandCategoryName) b. you can add more sample/test by refer example in this file - You may remove all others folder in
backend/test/documents/*and remain onlycategoryso we can have success test - execute test by run command
npm run test:e2ein your backend
Every test shall implement independently, in the case of product which depends on category records, we can:
- copy/modify partial of record from
backend/test/category/category.e2e-spec.tsintobackend/test/product/product.e2e-spec.ts - execute insert
categoryusingbeforeAll, you may refer: a. nestjs test documentation b. jest test order
- Test shall implement in empty database cause we don't want primary key crash
- put sample data in stub cause we don't want our code accidentally modify the sample data
- default test is simplest approach, every additional api require additional test
- every test shall:
a. test http status
b. when data effect database, shall continue verify result using subsequent step
then