Skip to content

Commit

Permalink
Merge pull request #5 from laineveeti/dotenv
Browse files Browse the repository at this point in the history
moved env variables to encrypted .env.ci file and fixed remaining issues with tests

merging without approving review because couldn't reach teacher
  • Loading branch information
piisamirontta authored Aug 11, 2024
2 parents a358aab + 7d45d7a commit 0cdb43d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 12 deletions.
11 changes: 11 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -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="
18 changes: 10 additions & 8 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
build/
.env
.env
.env.keys
7 changes: 7 additions & 0 deletions controllers/testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/bloglist.cy.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Binary file modified frontend/cypress/videos/bloglist.cy.js.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0cdb43d

Please sign in to comment.