Skip to content

Commit

Permalink
Merge pull request #183 from mate-academy/add-test
Browse files Browse the repository at this point in the history
test run
  • Loading branch information
alexandra-protyanova authored Feb 2, 2024
2 parents b50b280 + ea94c06 commit 6828bc3
Show file tree
Hide file tree
Showing 12 changed files with 4,429 additions and 10,457 deletions.
45 changes: 33 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,43 @@ name: Test

on:
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x]

node-version: [14.x]
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: students
POSTGRES_PORT: 5432
POSTGRES_HOST: localhost
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: students
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
run: npm test
14,205 changes: 3,763 additions & 10,442 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
"license": "GPL-3.0",
"devDependencies": {
"@mate-academy/eslint-config": "*",
"@mate-academy/scripts": "^1.2.3",
"@mate-academy/scripts": "^1.7.0",
"axios": "^1.6.5",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
"jest": "^24.7.0"
"jest": "^29.7.0"
},
"mateAcademy": {
"projectType": "javascript"
"projectType": "nodeJs"
},
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
"pg": "^8.11.3",
"sequelize": "^6.35.2"
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ Take the Accounting app from prev lesson and use PostgreSQL as a storage

- Implement CRUD page to manage categories

# Note
- You can sync models by running `npm run test`
- in local env, tests interect with your local database, so rows can be changed or removed


**Read [the guideline](https://github.com/mate-academy/js_task-guideline/blob/master/README.md) before start**
9 changes: 9 additions & 0 deletions src/createServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const createServer = () => {
// your code goes here
};

module.exports = {
createServer,
};
34 changes: 34 additions & 0 deletions src/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const { Sequelize } = require('sequelize');
const utils = require('util');

// Needed for testing purposes, do not remove
require('dotenv').config();
global.TextEncoder = utils.TextEncoder;

const {
POSTGRES_HOST,
POSTGRES_PORT,
POSTGRES_USER,
POSTGRES_PASSWORD,
POSTGRES_DB,
} = process.env;

/*
All credentials setted to default values (exsept password - it is exapmle)
replace if needed with your own
*/

const sequelize = new Sequelize({
database: POSTGRES_DB || 'postgres',
username: POSTGRES_USER || 'postgres',
host: POSTGRES_HOST || 'localhost',
dialect: 'postgres',
port: POSTGRES_PORT || 5432,
password: POSTGRES_PASSWORD || '123',
});

module.exports = {
sequelize,
};
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
/* eslint-disable no-console */

'use strict';

const { createServer } = require('./createServer');

createServer()
.listen(5700, () => {
console.log('Server is running on localhost:5700');
});
11 changes: 11 additions & 0 deletions src/models/Expense.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const { sequelize } = require('../db.js');

const Expense = sequelize.define(
// your code goes here
);

module.exports = {
Expense,
};
11 changes: 11 additions & 0 deletions src/models/User.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const { sequelize } = require('../db.js');

const User = sequelize.define(
// your code goes here
);

module.exports = {
User,
};
11 changes: 11 additions & 0 deletions src/models/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const { User } = require('./User.model');
const { Expense } = require('./Expense.model');

module.exports = {
models: {
User,
Expense,
},
};
Loading

0 comments on commit 6828bc3

Please sign in to comment.