Skip to content

Commit

Permalink
Merge pull request #16 from akhilome/ch-dummy-data-160239312
Browse files Browse the repository at this point in the history
#160239312 Create Dummy Data
  • Loading branch information
akhilome committed Sep 5, 2018
2 parents 1d1a40a + ceced5f commit c52b581
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
32 changes: 32 additions & 0 deletions server/db/orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const orders = [
{
id: 1,
author: 'Michelle Graham',
title: 'Shrimps',
date: '2018-05-20',
status: 'pending',
},
{
id: 2,
author: 'Chrisette Clark',
title: 'Chicken & Chips',
date: '2018-05-21',
status: 'pending',
},
{
id: 3,
author: 'Jamiu Rafa',
title: 'Shrimps',
date: '2018-06-01',
status: 'pending',
},
{
id: 4,
author: 'Tomal Gardner',
title: 'Spiced Turkey',
date: '2018-06-04',
status: 'pending',
},
];

export default orders;
13 changes: 13 additions & 0 deletions server/models/Order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import todaysDate from '../utils/date';

class Order {
constructor(id, author, food) {
this.id = id;
this.author = author;
this.title = food;
this.status = 'pending';
this.date = todaysDate();
}
}

export default Order;
17 changes: 17 additions & 0 deletions server/utils/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function makeTodaysDate() {
const now = new Date(Date.now());
const [year, month, day] = [
now.getFullYear(),
now.getMonth(),
now.getDay(),
];

const padding = (num) => {
const padded = num > 10 ? `${num}` : `0${num}`;
return padded;
};

return `${year}-${padding(month)}-${padding(day)}`;
}

export default makeTodaysDate;
27 changes: 27 additions & 0 deletions tests/models/Order.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import chai from 'chai';
import 'chai/register-should';
import dirtyChai from 'dirty-chai';
import Order from '../../server/models/Order';
import todaysDate from '../../server/utils/date';

chai.use(dirtyChai);

describe('New order model', () => {
const order = new Order(1, 'Kizito Akhilome', 'Egg & Bread');

it('should return a non-empty object', () => {
order.should.be.an('object').that.is.not.empty();
});

it('should contain all the necessary properties', () => {
order.should.have.all.keys('id', 'author', 'title', 'status', 'date');
});

it('should contain the correct data', () => {
order.id.should.be.a('number').that.is.equal(1);
order.author.should.equal('Kizito Akhilome');
order.title.should.equal('Egg & Bread');
order.status.should.equal('pending');
order.date.should.equals(todaysDate());
});
});
24 changes: 24 additions & 0 deletions tests/utils/date.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import chai from 'chai';
import 'chai/register-should';
import dirtyChai from 'dirty-chai';
import makeTodaysDate from '../../server/utils/date';

chai.use(dirtyChai);

describe('Today\'s Date Utility Function', () => {
it('should be a function', () => {
makeTodaysDate.should.be.a('function');
});

it('should return a non-empty string', () => {
makeTodaysDate().should.be.a('string').which.is.not.empty();
});

it('should return today\'s date', () => {
const today = new Date(Date.now());
makeTodaysDate().should.be.a('string').that.has.a.lengthOf('YYYY-MM-DD'.length);
makeTodaysDate().should.be.a('string').which.includes(today.getDay());
makeTodaysDate().should.be.a('string').which.includes(today.getMonth());
makeTodaysDate().should.be.a('string').which.includes(today.getFullYear());
});
});

0 comments on commit c52b581

Please sign in to comment.