diff --git a/.env.ci b/.env.ci new file mode 100644 index 0000000..3a9e32c --- /dev/null +++ b/.env.ci @@ -0,0 +1,11 @@ +#/-------------------[DOTENV_PUBLIC_KEY]--------------------/ +#/ public-key encryption for .env files / +#/ [how it works](https://dotenvx.com/encryption) / +#/----------------------------------------------------------/ +DOTENV_PUBLIC_KEY_CI="0269b6d4328ebeb8f69a6b84f3c3f14ef6add5844eda2f6ac8676ea31362ed1709" + +# .env.ci +TEST_MONGODB_URI="encrypted:BAcJdC5MbFLLn/TIDcERs3zOOmoZj9JV4CsAmsYrxoihhn21GcP556J4g5Z8w32waOX5O3gyy1Iziw/KClIa03DXjK/YhH0JLgL4isy2QDBqO/A42CNBcCZOPuK/7ZaDFj4UlGhhZ6y/WRHIsDUpdt3Iiqnv7HrngxnXdIu5ezdRh2fgQpRG31hitVT7PjwIK1RAV4T2Q0Oa4GxtdGDqrWydm5ioevhswpM3PpH34fXLi3SDsJIaNGb/EyIuAh+ckuYDJNlunaOe07sSkCl+Vz07vUQIs8RMi9MlnWjhgPLZ//zi9QUe" +MONGODB_URI="encrypted:BPK5Uu6TTIKm1eszcOUTuFXtWZs9b7eNxnq7Zd6wyk/Z7NxGQxL3YNa8yOyEBTtAtmFqY3rsfffgHGkrw4VyIfxuO8EOFfC5z2axhTQEsHUtuEXgYtV3wGZQ0iDLhsogmvsc4wSGYBJ2z1XLJhD5YnJDUnvrZo1Min767UbX+ZAZ/b7MyFPsbRDXwwIEoe9CZCMdplTx+DKAk9/ljLZOSc7IcsDpwB5UE/q1CYLd4dj/pS51po6uLRY00CwE/nQ43RJ5G6beXbOmS+AGNksOR7n0QBMd90IeAkZWCQhUajgDNdgy" +DEV_MONGODB_URI="encrypted:BMLCT5PgRUp6ofpOGze+nWE9b0YpaTaZg6A/07XWeXLJbPwheui42lIWldG3xac/yj9Yxh5SMDec+jzIkCoRHFXrZQzPROZkOutwOSwyZbypBgkPANI0yD6nlPKwRkDlUlbPC/BDHP+ViL+tCTdujAXh+T+8OupRt2XOlPxLwZSpxJO8JKlbeM5uXWHwAgkxwDC3LtcKdhpnGI5kllCYLs3CJFlHqUYf8ic+55E8V05STj+cuI5ncbVYyU37dxZQdGOLD8YX7wlsa5v2nW/G68JrSw7DFIavLA2WAimMKCO0JbZptAs=" +SECRET="encrypted:BDxTEqQlCj0mYJWgVa2OigtNXJEKlN9p6wl8qS8T8pV7Y1oAOtjOdvAVRZzfED3c79urJHmzz7XEjH4pH7aGhdtVhGNvR8uxhtlfCHkAwUzhgFuY9jAHvYYuLRsGtGLaYlfodWinrFIK0myH1t5r2Ug/gms=" \ No newline at end of file diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index cfd33cc..18fca01 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -12,10 +12,6 @@ on: env: COMMIT_MESSAGES: ${{ toJson(github.event.commits.*.message) }} COMMIT: ${{ toJson(github.event.commits)[0] }} - SECRET: ${{ secrets.SECRET }} - MONGODB_URI: ${{ secrets.MONGODB_URI }} - TEST_MONGODB_URI: ${{ secrets.TEST_MONGODB_URI }} - DEV_MONGODB_URI: ${{ secrets.DEV_MONGODB_URI }} jobs: simple_deployment_pipeline: @@ -28,15 +24,21 @@ jobs: - run: npm install && cd frontend && npm install - run: npm run eslint && cd frontend && npm run eslint - run: npm run build - - run: npm run test + - run: curl -sfS https://dotenvx.sh/install.sh | sh + - name: backend tests + run: dotenvx run -- npm run test + env: + DOTENV_PRIVATE_KEY_CI: ${{ secrets.DOTENV_PRIVATE_KEY_CI }} - name: frontend tests run: cd frontend && npm run test - name: e2e tests uses: cypress-io/github-action@v5 with: - command: cd frontend && npm run cypress - start: npm run start - wait-on: http://localhost:5000 + command: npm run test:e2e + start: dotenvx run -- npm run start:e2e + wait-on: "http://localhost:3003, http://localhost:3000" + env: + DOTENV_PRIVATE_KEY_CI: ${{ secrets.DOTENV_PRIVATE_KEY_CI }} - name: deployment if: ${{ github.event_name == 'push' }} run: curl https://api.render.com/deploy/srv-${{ secrets.RENDER_SERVICE_ID }}?key=${{ secrets.RENDER_API_KEY }} diff --git a/.gitignore b/.gitignore index cd0234e..32415bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ build/ -.env \ No newline at end of file +.env +.env.keys diff --git a/controllers/testing.js b/controllers/testing.js index 919ef8f..356f2be 100644 --- a/controllers/testing.js +++ b/controllers/testing.js @@ -35,4 +35,11 @@ router.post('/reset', async (request, response) => { response.status(204).end(); }); +router.post('/empty', async (request, response) => { + await Blog.deleteMany({}); + await User.deleteMany({}); + + response.status(204).end(); +}); + module.exports = router; diff --git a/frontend/cypress/e2e/bloglist.cy.js b/frontend/cypress/e2e/bloglist.cy.js index 133f2ef..2bd36e1 100644 --- a/frontend/cypress/e2e/bloglist.cy.js +++ b/frontend/cypress/e2e/bloglist.cy.js @@ -1,7 +1,7 @@ /* eslint-disable no-undef */ describe('Bloglist app', function() { beforeEach(function() { - cy.request('POST', `${Cypress.env('BACKEND')}/testing/reset`); + cy.request('POST', `${Cypress.env('BACKEND')}/testing/empty`); const user = { name: 'Testi Käyttäjä', username: 'testuser', diff --git a/frontend/cypress/videos/bloglist.cy.js.mp4 b/frontend/cypress/videos/bloglist.cy.js.mp4 index c0b6ab1..a2480ec 100644 Binary files a/frontend/cypress/videos/bloglist.cy.js.mp4 and b/frontend/cypress/videos/bloglist.cy.js.mp4 differ diff --git a/index.js b/index.js index 3d297f6..d228f64 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const app = require('./app'); const server = http.createServer(app); -const PORT = config.PORT || 3001; +const PORT = config.PORT || 3003; server.listen(PORT, () => { logger.info(`Server running on port ${config.PORT}`); diff --git a/package.json b/package.json index 47fce34..a618727 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "render:deploy": "npm install && cd frontend && npm install && npm run build", "eslint": "eslint .", "test": "NODE_ENV=testing jest --verbose --runInBand --forceExit", - "start:test": "NODE_ENV=testing node index.js" + "start:test": "NODE_ENV=testing node index.js", + "start:e2e": "npm run start:test & cd frontend && npm run start", + "test:e2e": "cd frontend && npm run cypress" }, "author": "", "license": "ISC",