-
Notifications
You must be signed in to change notification settings - Fork 10
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
Testing setup #142
Testing setup #142
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good!
@@ -19,6 +19,7 @@ services: | |||
- "9091:9091" # for debugging metrics | |||
volumes: | |||
- ./packages/server/src:/court-backend/packages/server/src | |||
- ./packages/server/test:/court-backend/packages/server/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for adding the test dir here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can update and run tests while developing without rebuilding the container, much faster this way
"morgan": "^1.9.1", | ||
"objection": "^2.1.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing dependencies should be devDependencies
actually
@@ -25,13 +25,12 @@ export default () => { | |||
}) | |||
|
|||
return session({ | |||
store, | |||
key: 'aragonCourtSessionID', | |||
// store, // I disabled this for now because it doesn't work and I will be migrating to Objection in the next PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this PR once we have the whole refactor then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But front end guys need something functional right now so we can have it working like this (as it was working in my first implementation already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we simply store a session for the users then? It would be simply doing this I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh if it's so simple I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm in order to make this work your model forces me to use users table but I don't want to touch it right now while we are still actively developing. I would prefer to merge this in memory solution now while I figure out the storage stuff which will still take a day or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added your fix, thanks!
resave: false, // Don't force sessions to be saved back to the store even if they didn't change | ||
saveUninitialized: false, // Don't force uninitialized session to be saved to the store | ||
secret: process.env.SESSION_SECRET, // Secret used to generate session IDs | ||
name: 'aragonCourtSessionID', // Cookie name to be used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -10,6 +10,9 @@ export default app => { | |||
// check user details | |||
app.get( '/users/:address', asyncMiddleware(users.details)) | |||
|
|||
// verify user email using provided token (needs to come before sessions to avoid session authentication) | |||
app.post( '/users/:address/email[:]verify', asyncMiddleware(users.email.verify)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have something similar to what we did with the admin authenticated routes. I prefer being explicit than depend on how we order routes, we can mess it up easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this requires a separate controller, which also requires model, which will depend on storage, I prefer to do this in the next PR
// agent is used to persist authentication cookie across multiple tests | ||
const agent = chai.request.agent(`http://localhost:${serverPort}`); | ||
|
||
describe("Server Endpoints", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know #134 hasn't been implemented yet, but let's try to use single quotes for all strings and no semicolons 🙏
chai.use(chaiHttp); | ||
|
||
// agent is used to persist authentication cookie across multiple tests | ||
const agent = chai.request.agent(`http://localhost:${serverPort}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proper way to do this with mocha is to use a before
statement and an after
statement to close it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm before statement doesn't work, agent variable needs to be reachable inside other it
scopes. I can only use after
to close it.
@@ -10,7 +10,8 @@ | |||
"scripts": { | |||
"build": "babel ./src --out-dir ./build --source-maps --copy-files", | |||
"start": "npm run build && ./scripts/db-setup.sh && node ./build", | |||
"start:dev": "./scripts/db-setup.sh && nodemon --ignore ./build --exec babel-node ./src/index.js" | |||
"start:dev": "./scripts/db-setup.sh && nodemon --ignore ./build --exec babel-node ./src/index.js", | |||
"test": "npx mocha test --recursive" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏👏👏👏
.github/workflows/testnet.yml
Outdated
export SERVER_IMAGE=$REPO:${GITHUB_SHA} | ||
docker-compose up -d | ||
sleep 10 | ||
docker-compose exec -T court_server npm run test:server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a way to have a shared testing workflow that both deployments could depend on instead of having it repeated for both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good idea, I will add a shared shell script.
@@ -2,7 +2,10 @@ name: Testnet CI/CD | |||
on: | |||
push: | |||
branches: | |||
- development | |||
# Executes on any non master commit, but release and deploy steps only run on development | |||
# This is useful to see if tests are passing during PR review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure :)
* set up continuous testing for server endpoints * added ci/cd branch wildcard * fixed ci/cd files * fixed conditional ref * added missing checkout and better docker caching * run all test actions in a single script * switch places docker --cahce-from for rolling updates first * disabled tty for docker-compose exec * added missing checkout for master ci/cd * added sleep 10 before running test * use single quotes and no semicolons * small fixes * moved some ci/cd logic into shared shell scripts * made scripts executable * added .git to dockerignore for better caching * cherry pick session storage fix * re-enabled session storage Co-authored-by: Facu Spagnuolo <[email protected]>
Added continuous testing for every commit. This way we can see if all tests are passing while reviewing a PR. Tests are continuously running and creating an image with a
:rolling
tag. When we finally merge into development/master+tag that rolling image is tagged with:latest
/:v*
and deployed to k8s.Currently for testing I just set up a server+postgres with docker-compose and check all localhost api endpoints for correct response. We can add more tests later on.
Tests can also be run locally using
docker-compose exec court_server npm run test:server
.This also temporarily fixes the session bug that was blocking front end development.