Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Region tests #308

Merged
merged 21 commits into from
May 10, 2023
Merged

Region tests #308

merged 21 commits into from
May 10, 2023

Conversation

ludverst
Copy link
Contributor

Beschrijving & Testmethode

Deze testen testen op de verschillende scenario's voor het regio-model, waaronder geslaagde requests, niet-succesvolle requests vanwege autorisatie, niet-bestaande paden en onjuiste typen regio-id's.

Aanpassingen

  • Bug fix (non-breaking wijziging die een probleem oplost)
  • New feature (non-breaking wijziging met nieuwe functionaliteit)
  • Breaking change (bestaande functionaliteit breekt door deze aanpassingen)

Checklist

  • De code volgt de stijl en guidelines van dit project.
  • Vereist een aanpassing aan de documentatie.
  • De documentatie is gewijzigd.

Close #307

@ludverst ludverst added api Werking van onze REST API test Heeft te maken met testen van functionaliteit labels Apr 27, 2023
@ludverst ludverst self-assigned this Apr 27, 2023
@ludverst ludverst linked an issue Apr 27, 2023 that may be closed by this pull request
ArnoutAllaert
ArnoutAllaert previously approved these changes Apr 27, 2023
Copy link
Contributor

@TheMessik TheMessik left a comment

Choose a reason for hiding this comment

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

Deze test suite voelt onvolledig aan. Ik zie bijvoorbeeld geen testen die over de user_region gaan en ik zou deze integratie toch wel graag getest zien.

Het is een goede aanzet, maar graag iets verder denken.

Comment on lines 179 to 181
afterAll(() => {
app.close();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Deze afterAll werkt enkel binnen de "Successful requests" blok. Deze moet in de buitenste blok komen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Er staat ook een afterAll in "Unsuccesful requests". Is het beter om maar 1 keer afterAll te doen in de buitenste block?

Copy link
Contributor

Choose a reason for hiding this comment

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

Het gaat er niet om maar 1x te doen.
In de afterAll staat app.close(). Nu blijkt dat de testen alsnog verder kunnen, blijkbaar dankzij de requests library, maar het is overbodig deze resource 2x vrij te geven. Het doet hier geen kwaad, maar we hoeven ons niet onnodig te herhalen

api/__tests__/routes/region.test.ts Show resolved Hide resolved
Comment on lines 298 to 312
test("Find a nonexistent region", async () => {
await runner.get({
url: "/region/-1",
expectedData: [notFoundResponse],
statusCode: 404,
});
});

test("Update a nonexistent region", async () => {
await runner.get({
url: "/region/0",
expectedData: [notFoundResponse],
statusCode: 404,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Hetzelfde comment hier als in mijn review van Round tests. Ofwel neem deze testen samen, ofwel noem ze anders.

@ludverst
Copy link
Contributor Author

ludverst commented May 3, 2023

TODO:

  • soft delete testen

@jenspots jenspots marked this pull request as draft May 4, 2023 12:04
@ludverst ludverst marked this pull request as ready for review May 5, 2023 09:41
@ludverst ludverst requested a review from TheMessik May 5, 2023 09:42
Copy link
Contributor

@TheMessik TheMessik left a comment

Choose a reason for hiding this comment

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

Nog een paar kleine aanpassingen vereist.

api/__tests__/routes/region.test.ts Show resolved Hide resolved
@@ -176,8 +176,78 @@ describe("Region tests", () => {
});
});

afterAll(() => {
app.close();
describe("path for admin", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Als je maar 1 test hebt, hoef je er geen nieuwe test suite met describe van maken. De code in beforeEach kan je simpelweg bovenaan je test plaatsen.

});
});
});
describe("Cannot reach any path as a student", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Er ontbreken tests voor updateOne en getOne.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

een student kan momenteel voor elke id getOne doen. Ik heb daar een issue voor aangemaakt #355. Ik zal in deze issue de testen aanvullen voor getOne

@ludverst ludverst requested a review from TheMessik May 5, 2023 18:02
@TheMessik
Copy link
Contributor

TheMessik commented May 10, 2023

API testen falen wegens een bug in validators, het zou gefixt moeten worden door #382

All validators have been updated to correctly refer to the id in params,
using the correct celebrate syntax
@TheMessik
Copy link
Contributor

De bug bleek door #382 juist geintroduceerd te worden, dit is nu gefixt

@codecov
Copy link

codecov bot commented May 10, 2023

Codecov Report

Merging #308 (e032b3b) into develop (c7146fd) will increase coverage by 1.89%.
The diff coverage is 100.00%.

❗ Current head e032b3b differs from pull request most recent head f7351d1. Consider uploading reports for the commit f7351d1 to get more accurate results

@@             Coverage Diff             @@
##           develop     #308      +/-   ##
===========================================
+ Coverage    83.34%   85.24%   +1.89%     
===========================================
  Files           41       41              
  Lines         1093     1098       +5     
  Branches       221      223       +2     
===========================================
+ Hits           911      936      +25     
+ Misses         147      135      -12     
+ Partials        35       27       -8     
Impacted Files Coverage Δ
api/src/routes/region.ts 93.93% <100.00%> (+40.36%) ⬆️
api/src/validators/action.validator.ts 100.00% <100.00%> (ø)
api/src/validators/address.validator.ts 100.00% <100.00%> (ø)
api/src/validators/building.validator.ts 100.00% <100.00%> (ø)
api/src/validators/garbage.validator.ts 100.00% <100.00%> (ø)
api/src/validators/mailtemplate.validator.ts 100.00% <100.00%> (ø)
api/src/validators/progress.validator.ts 100.00% <100.00%> (ø)
api/src/validators/region.validator.ts 100.00% <100.00%> (ø)
api/src/validators/round.validator.ts 100.00% <100.00%> (ø)
api/src/validators/round_building.validator.ts 100.00% <100.00%> (ø)
... and 3 more

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@TheMessik TheMessik left a comment

Choose a reason for hiding this comment

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

Goede vooruitgang, nog een paar kleine aanpassingen vereist.

{ deleted: false, id: 3, name: "Region 3", users: [] },
];
await runner.get({
url: "/region",
Copy link
Contributor

Choose a reason for hiding this comment

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

Deze test wordt als super student gerunt zonder hardDelete flag, dus er zal soft delete uitgevoerd worden. Verder vraag je niet de deleted velden specifiek op, dus je merkt ook niet dat er zaken soft deleted zijn.

});
});

afterAll(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Dit hoort hier niet te staan.

@jenspots jenspots removed the request for review from ArnoutAllaert May 10, 2023 13:37
@jenspots jenspots merged commit 6802276 into develop May 10, 2023
@jenspots jenspots deleted the api/test/route-region branch May 10, 2023 13:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api Werking van onze REST API test Heeft te maken met testen van functionaliteit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: Testen voor region route
4 participants