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

Make sure that DB state is properly reset between execution of each API test suite #684

Closed
adrienjoly opened this issue Aug 28, 2023 · 0 comments · Fixed by #688
Closed
Assignees
Labels

Comments

@adrienjoly
Copy link
Member

adrienjoly commented Aug 28, 2023

cf #680.

@adrienjoly adrienjoly added the bug label Aug 28, 2023
@adrienjoly adrienjoly self-assigned this Aug 28, 2023
adrienjoly added a commit that referenced this issue Aug 28, 2023
adrienjoly added a commit that referenced this issue Aug 28, 2023
…685)

Contributes to #684.

* fix test helpers based on trouble while working on PR #680

* fix: check that we're on test database before refreshing db caches

* report cleanup errors if any

* fixtures: make test users immutable

* 🧹 `failed to kill by pid: kill ESRCH` errors when running integration/api tests

* skip flaky unit test

* migrate playlist API tests to `OpenwhydTestEnv`

* fix `listen EADDRINUSE: address already in use :::8080` when api tests are running on CI, with coverage
cf https://github.com/openwhyd/openwhyd/actions/runs/6000177975/job/16271736742#step:6:266

* refactor(fixtures): extract resetTestDb() from cleanup()

* ✨ use OpenwhydTestEnv.reset() instead of fixtures.cleanup(), in playlist API tests

* extract and increase timeout/tolerance for algolia (3rd-party) tests
cf `Exceeded timeout of 20000 ms for a hook` at https://github.com/openwhyd/openwhyd/actions/runs/6000432446/job/16272475960#step:5:81
adrienjoly added a commit that referenced this issue Aug 28, 2023
Contributes to #684.

Guidelines: In order to ensure isolation of tests, make sure to run reset() or resetTestDb() before the execution of every test.

Changes:

* remove one FIXME, in playlist.api.tests.js

* use DUMMY_USER in post API tests => remove 2nd FIXME

* 🔴 add test: `rename` action should rename a playlist

* workaround to fix playlist api test: allow login by overriding `pwd` prop
cf https://github.com/openwhyd/openwhyd/actions/runs/6001268681/job/16275071747#step:6:173

* refactor(helpers): extract getURL() method

* 🔴 deleting users should not impact other tests, thanks to `openwhyd.reset()`

* fix call to resetTestDb()
adrienjoly added a commit that referenced this issue Aug 29, 2023
…Env` (#688)

Fixes #684.

Follow up of PR #687.

Improvements:
- Make sure that db state is reset everywhere it needs to be, ideally before each test, to ensure state isolation and prevent side effects.
- Use `OpenwhydTestEnv.reset()` instead of `fixtures.cleanup()`, where applicable.

Commits:

* fix(tests): use `OpenwhydTestEnv.reset()` where applicable

* fix: refresh cache on reset()

* display reset logs when silent==false

* revert to silent=true

* fix use of reset in API tests

* fix assertion now that post API tests are isolated

* fix(sonar): call to openwhyd.reset()

* make db reset logs silent

* auth api tests: prevent side effects between tests by resetting db state

* data api tests: prevent side effects between tests by resetting db state

* follow api tests: prevent side effects between tests by resetting db state

* legacy post api tests: prevent side effects between tests by resetting db state

* legacy post api: isolate tests

* optim: re-use jar / session

* post api: improve legibility

* 🧹 remove logs `[cleanup] reset.controller deleting` ...

* post api: harmonize place to init OpenwhydTestEnv

* harmonize calls to reset()

* fixtures.js: improve documentation and typing

* get URL_PREFIX dynamically from OpenwhydTestEnv instance => move default value from fixtures.js to api-client.js

* try to prevent `E11000 duplicate key error collection: openwhyd_test.user index: _id_ dup key: { : ObjectId('000000000000000000000001') }` error,
observed once on `"before each" hook for "should return tracks if two limit parameters are provided"`

* consistency: use `openwhyd` as name for `OpenwhydTestEnv` instances

* improve documentation of OpenwhydTestEnv
adrienjoly added a commit that referenced this issue Aug 29, 2023
Follow-up of #688 and #684.

* fix(tests): fix 1st TS error in `startOpenwhydServerWith`

* fix(tests): fix remaining TS errors in `OpenwhydTestEnv`

* fix typescript and execution errors
cf:
- `The "path" argument must be of type string or an instance of Buffer or URL. Received undefined` from https://github.com/openwhyd/openwhyd/actions/runs/6012433632/job/16307786355?pr=689#step:6:128 (`$ make test-in-docker`)
- `please call setup() before getEnv()` from https://github.com/openwhyd/openwhyd/actions/runs/6012433632/job/16307784251?pr=689#step:6:77 (`$ make test-approval`)

* flexibility: late evaluation of port, if not provided in process.env
adrienjoly added a commit that referenced this issue Aug 29, 2023
Contributes to #634.

* fix callbacks passed to mongodb, in post model

* fix counter of refs to deprecated `usernames` cache
cause: some refs were probably not detected earlier, because of complicated callback logic
contributes to #580.

* fix(codacy): Always provide a base when using parseInt() functions

* check for TypeScript errors in `post.js`

* fix `Property 'nbPostsPerNewsfeedPage' does not exist on type 'typeof import("/Users/adrienjoly/Code/openwhyd/app/models/config")'`

* fix deprecated mongodb options

* fix `Cannot read properties of undefined (reading 'nbPostsPerNewsfeedPage')`
cf https://github.com/openwhyd/openwhyd/actions/runs/5983938243/job/16234633467?pr=680#step:7:22

* add test: `incrPlayCounter` action should increase the number of plays of the track

* add failing test: `incrPlayCounter` action should return the post _id

* fix(api): incrPlayCounter action to not return the `post` object anymore
!BREAKING

* add failing test: `should increase the total number of plays of that track` => make sure that db is cleared between each test

* fix test `post api should add a track to a new playlist`, to make it isolated/independant from other tests of the suite

* fix test: `should increase the total number of plays of that track`, as `track` documents are created lazily

* test should not pass => make `updateByEid` assert that `eId` param is defined

* fix test by setting a eId

* fix `incrPlayCounter` impl. by fetching the post's eId

* playlist tests: prevent side effects between tests

* refactor: extract callPlaylistApi

* playlist tests: use DUMMY_USER instead of ADMIN_USER

* playlist tests: make sure that freshly created playlist is persisted in db

* add test: should rename a playlist

* add failing test: should update the playlist's name in associated posts

* fix: userModel.setPlaylist to await the update of posts

* fix test, to match with schema of posts

* be more decisive on when to cleanup, in post.api.tests.js

* skip tests that cause side effects on other tests
example for #684.

* fix(sonar): `Promise returned in function argument where a void return was expected.`

* 🙌 re-enable all playlist api tests

* remove callback from setPlaylist()

* add tests for playlist removal and its impact on associated posts

* remove callback from unsetPlaylist()

* fix some error cases, based on code review

* simplify call expression

* refactor: move up insertPost() and callPostApi() helpers

* add tests for toggleLovePost

* reveal missing callbacks in setPostLove

* remove callback from setPostLove()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant