Skip to content
Open

Test #94

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nyc_output/39af4d8ef6083b37b602e5783860a3dd.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .nyc_output/76c5a175b339a70bc2e7e29ac384515c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions .nyc_output/90d81046775b082d3a3880376538adab.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions .nyc_output/d48487ca8c0c291905a6e37349697a46.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
"description": "### 1 - Idea :- Build Website that have a benefit to manage inventory in easy way by software rather than manage it by traditional way using paper. And make the process of tracking goods easier. <br>",
"main": "index.js",
"scripts": {
"test": "node test/back-end-test.js | tap-spec",
"test": "tape test/**/*.js | tap-spec",
"coverage": "nyc npm run test",
"start": "node src/server.js",
"start:watch": "nodemon src/server.js"
"start:watch": "nodemon src/server.js",
"lint": "semistandard --fix"
},
"pre-commit": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "git+https://github.com/FACG2/Inventory-Management-System.git"
Expand All @@ -34,8 +39,10 @@
},
"devDependencies": {
"chart.js": "^2.7.0",
"eslint": "^4.8.0",
"nodemon": "^1.12.1",
"nyc": "^11.2.1",
"pre-commit": "^1.2.2",
"supertest": "^3.0.0",
"tap-spec": "^4.1.1",
"tape": "^4.8.0"
Expand Down
6 changes: 3 additions & 3 deletions src/models/Database/db_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const {Pool} = require('pg');
require('env2')('./config.env');
let dataUrl;

if (!process.env.DATABASE_URL) {
process.env.NODE_ENV === 'test' ? dataUrl = process.env.TEST_URL : dataUrl = process.env.DATABASE_URL;

if (!dataUrl) {
throw new Error('No DATABASE_URL provided');
}

process.env.NODE_ENV === 'test' ? dataUrl = process.env.TEST_URL : dataUrl = process.env.DATABASE_URL;

module.exports = new Pool({connectionString: dataUrl, ssl: true});
24 changes: 7 additions & 17 deletions src/models/db_functions/goodsFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,16 @@ const deleteGoods = (good, cb) => {

const addGoods = (req, cb) => {
dbConnection.query({
text: `SELECT * FROM inventories WHERE id=$1`,
values: [req.invId]
}, (err, inventory) => {
if (err) {
cb(err);
} else {
const sql = `INSERT INTO goods (name, quantity, type, charge_date, image, expiry_date, inventory_id)
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING *;`;
dbConnection.query({
text: sql,
values: [req.body.goodName, req.body.goodQuantity, req.body.goodType, req.body.chargeDate, req.imageName, req.body.expiryDate, inventory.rows[0].id]},
text: `INSERT INTO goods (name, quantity, type, charge_date, image, expiry_date, inventory_id)
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING *;`,
values: [req.body.goodName, req.body.goodQuantity, req.body.goodType, req.body.chargeDate, req.imageName, req.body.expiryDate, req.invId]},
(error, res1) => {
if (error) {
cb(error);
} else {
cb(null, res1.rows);
}
});
}
});
};

const getAllGoods = (id, cb) => {
Expand Down Expand Up @@ -90,10 +80,10 @@ const getGoodById = (id, cb) => {
};

module.exports = {
addGoods,
addGoods, // ddone
deleteGoods,
getAllGoods,
updateGoods,
getAllGoods, // done
updateGoods, // done
update,
getGoodById
getGoodById // done
};
57 changes: 57 additions & 0 deletions test/back-end-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,47 @@ test('GET /goods/report (unauthenticated) should redirect to home page', t => {
.expect('Content-Type', 'text/plain; charset=utf-8')
.end((err, res) => {
t.equal(res.headers.location, '/', 'shoud return to home page');
t.same(res.statusCode, 302, 'Status code is 302');
console.log(err);
t.error(err, 'No error');
t.end();
});
});

test('All routes should return the expected results', t => {
request(app)
.get('/goods/add')
.expect(404)
.expect('Content-Type', 'text/html; charset=utf-8')
.end((err, res) => {
console.log(err);
t.same(res.statusCode, 404, 'Status code is 404');
console.log(err);
t.error(err, 'No error');
t.end();
});
});

test('All routes should return the expected results', t => {
request(app)
.get('/goods/:id')
.expect(404)
.expect('Content-Type', 'text/html; charset=utf-8')
.end((err, res) => {
console.log(err);
t.same(res.statusCode, 404, 'Status code is 404');
console.log(err);
t.error(err, 'No error');
t.end();
});
});

test('All routes should return the expected results', t => {
request(app)
.get('/goods/report')
.expect(302)
.expect('Content-Type', 'text/plain; charset=utf-8')
.end((err, res) => {
t.same(res.statusCode, 302, 'Status code is 302');
t.error(err, 'No error');
t.end();
Expand All @@ -71,6 +112,22 @@ test('GET /goods/add (unauthenticated) should redirect to home page', t => {
.send(newGoods)
.expect(302)
.expect('Content-Type', 'text/plain; charset=utf-8')
.end((err, res) => {
t.same(res.statusCode, 302, 'Status code is 302');
t.same(res.body.goodName, res.body.goodQuantity, res.body.goodType, res.body.chargeDate, res.imageName, res.body.expiryDate);
t.error(err, 'No error');

t.end();
});
});

test('Should edit goods', t => {
const good = { id: 1, goodName: 'قميص', quantity: 10, goodType: 'قطن', image: 'warehouse1.jpg' };
request(app)
.post('/goods/edit')
.send(good)
.expect(302)
.expect('Content-Type', 'text/plain; charset=utf-8')
.end((err, res) => {
t.equal(res.headers.location, '/', 'shoud return to home page');
t.same(res.statusCode, 302, 'Status code is 302');
Expand Down
Loading