Last active
September 26, 2016 19:19
-
-
Save cesarhdz/1e410530d9e22d8021ad2bd8ca6eda8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fixtures = require('./fixtures.json'); | |
var assert = expect; | |
describe('Line', function(){ | |
// setup | |
var state = [fixtures.courseLine, fixtures.serviceLine]; | |
function mapCurrency(line){ | |
return line.currency; | |
} | |
it('Should remove a line', function(){ | |
// given | |
var line = state[1]; | |
var payload = {line: line}; | |
var next = [fixtures.courseLine]; | |
// when | |
var result = removeLine(state, payload); | |
// then | |
expect(result).toEqual(next); | |
// Where line.type != 'CourseVariant' | |
}); | |
it('Should not remove a courseLine', function(){ | |
// given | |
var line = state[0]; | |
var payload = {line: line}; | |
var type = 'CourseVariant'; | |
assert(line.type).toEqual(type); | |
// and | |
var next = state; | |
// when | |
var result = removeLine(state, payload); | |
// then | |
expect(result).toEqual(next) | |
}); | |
it('Should add an Agency line with given currencies', function(){ | |
//given | |
var cmd = { | |
name: 'Line C', | |
qty: 1, | |
unit: 'Month', | |
currency: 'USD', | |
total: 25.00, | |
startDate: '2016-10-10' | |
} | |
var newLine = { | |
name: 'Line C', | |
qty: 1, | |
unit: 'Month', | |
currency: 'USD', | |
startDate: '2016-10-10', | |
items: [ | |
{ | |
name: "Line C", | |
total: 25.00, | |
type: 'BasePrice', | |
discount: [] | |
} | |
] | |
} | |
var next = state.concat([newLine]) | |
// when | |
var result = addLine({cmd: cmd}); | |
// then | |
expect(result).toEqual(next); | |
}); | |
it('Should not add a line with a currency that is not currently in the quote', function(){ | |
// given | |
var currencies = ['USD', 'CAD']; | |
assert(state.map(mapCurrency)).toEqual(currencies); | |
// and | |
var cmd = { | |
name: 'Admin Fee', | |
currency: 'MXN' | |
} | |
var next = state; | |
// when | |
var result = addLine({cmd: cmd}); | |
// then | |
expect(result).toEqual(next); | |
}) | |
it('Should update line name, startDate and unit', function(){ | |
// given | |
var cmd = { | |
name: 'Line X', | |
startDate: '2015-04-05', | |
unit: 'Month' | |
} | |
var line = state[1]; | |
var next = { | |
name: 'Line X', | |
qty: 2, | |
unit: 'Month', | |
vendor: {id: 2, vendorType: 'Agency'}, | |
currency: 'CAD', | |
type: 'Accommodation', | |
items: [ | |
{ | |
name: 'Item B1', | |
type: 'BasePrice', | |
total: 50, | |
discount: [] | |
} | |
] | |
} | |
// when | |
var result = udpateLine({cmd: cmd, line: line}); | |
// then | |
expect(result).toEqual(next); | |
}); | |
}) | |
describe('Item', function(){ | |
// setup | |
var line = fixtures.courseLine; | |
var state = [line]; | |
it('Should remove an item', function(){ | |
var payload = {line: line, item: line.items[2]}; | |
var next = [ | |
{ | |
name: 'Item A1', | |
type: 'Base', | |
total: 100.0, | |
discount: [{id: 2, name: 'Promo A1', total: 25.0}] | |
} | |
]; | |
//when | |
var result = removeItem(state, payload); | |
// then | |
expect(result[0].items).toEqual(next); | |
}); | |
it('Should not remove an item of type BasePrice', function(){ | |
var item = line.items[0]; | |
var payload = {line: line, item: item}; | |
var next = state; | |
//when | |
var result = removeItem(state, payload); | |
// then | |
expect(item.type).toEqual('BasePrice'); | |
expect(result).toEqual(next); | |
//@TODO Check an exception is thrown | |
}); | |
it('Should add CustomFee|Seassonal', function(){ | |
// given | |
var payload = { | |
line: line, | |
cmd: { | |
name: 'Item B', | |
total: 25.00, | |
type: 'CustomFee' | |
} | |
}; | |
var next = [ | |
line.items[0], | |
line.items[1], | |
{ | |
name: 'Item B', | |
type: 'CustomFee', | |
total: 25.00 | |
} | |
]; | |
// when | |
var result = addItem(state, payload); | |
// then | |
expect(result.items).toEqual(next); | |
// where type in ('CustomFee', 'Seassonal') | |
}); | |
it('Should not add an item with type other than CustomFee|Seassonal', function(){ | |
// given | |
var payload = { | |
line: line, | |
cmd: { | |
name: 'Item B', | |
total: 25.00, | |
type: 'BasePrice' | |
} | |
}; | |
var next = state; | |
// when | |
var result = addItem(state, payload); | |
// then | |
expect(result.items).toEqual(next); | |
// where type in ('CustomFee', 'Seassonal') | |
}); | |
it('Should update item name and total', function(){ | |
// given | |
var item = line.item[0]; | |
var payload = { | |
item: item, | |
cmd: { | |
name: 'Item X', | |
total: 99.99, | |
} | |
}; | |
var next = { | |
name: "Item X", | |
type: "Base", | |
total: 99.99, | |
discount: [ | |
{ | |
id: 2, | |
name: "Promo A1", | |
total: 25.0 | |
} | |
] | |
}; | |
// when | |
var result = addItem(state, payload); | |
// then | |
expect(result.items).toEqual(next); | |
// where type in ('CustomFee', 'Seassonal') | |
}) | |
}); | |
describe('Promotion', function(){ | |
// Setup | |
var line = fixtures.courseLine; | |
var state = [line]; | |
it('Should remove promotion', function(){ | |
// given | |
var item = line.items[0]; | |
var payload = { | |
item: item, | |
promo: item.discount[0] | |
}; | |
var next = { | |
name: 'Item A1', | |
type: 'Base', | |
total: 100.0, | |
discount: [] | |
}; | |
// when | |
var result = removePromotion(state, payload); | |
// then | |
expect(result[0].items[0]).toEqual(next); | |
}); | |
it('Should add a promotion', function(){ | |
// given | |
var item = line.items[1]; | |
var payload = { | |
item: item, | |
promo: {'Promo B1', total: 10.0 } | |
}; | |
var next = { | |
name: 'Item A2', | |
type: 'TuitionFee', | |
total: 20, | |
discount: [{name: 'Promo B1', total: 10.0 }] | |
} | |
// when | |
var result = addPromotion(state, payload) | |
// then | |
expect(result[0].items[1]).toEqual(next); | |
}); | |
it('Should update a promotion name|total', function(){ | |
var item = line.items[0]; | |
var payload = { | |
promotion: item.discount[0], | |
cmd: { | |
name: 'Updated Promotion', | |
total: 23.00 | |
} | |
}; | |
var next = { | |
name: 'Item A1', | |
type: 'Base', | |
total: 100.0, | |
discount: [{id: 2, name: 'Updated Promotion', total: 23.0}] | |
}; | |
// when | |
var result = updatePromotion(state, payload); | |
// then | |
expect(result[0].items[0]).toEqual(next); | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"courseLine": { | |
"name": "Line A", | |
"qty": 1, | |
"unit": "Week", | |
"vendor": {"id": 1, "vendorType": "Institute"}, | |
"currency": "USD", | |
"startDate": "2016-10-01", | |
"type": "CourseVariant", | |
"items": [ | |
{ | |
"name": "Item A1", | |
"type": "BasePrice", | |
"total": 100.0, | |
"discount": [ | |
{ | |
"name": "Promo A1", | |
"total": 25.0 | |
} | |
] | |
}, | |
{ | |
"name": "Item A2", | |
"type": "TuitionFee", | |
"total": 20, | |
"discount": [] | |
} | |
] | |
}, | |
"serviceLine": { | |
"name": "Line B", | |
"qty": 2, | |
"unit": "Service", | |
"vendor": {"id": 2, "vendorType": "Agency"}, | |
"currency": "CAD", | |
"type": "Accommodation", | |
"items":[ | |
{ | |
"name": "Item B1", | |
"type": "BasePrice", | |
"total": 50, | |
"discount": [] | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment