Skip to content

Instantly share code, notes, and snippets.

@zacck-zz
Created September 26, 2016 12:10
Show Gist options
  • Save zacck-zz/b6de9f3f52bd64bc2b59ec90a8628624 to your computer and use it in GitHub Desktop.
Save zacck-zz/b6de9f3f52bd64bc2b59ec90a8628624 to your computer and use it in GitHub Desktop.
/*Add dependencies for testing actions*/
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import expect from 'expect';
import firebase, {firebaseRef} from 'app/firebase';
import moment from 'moment';
import * as actions from 'app/actions/actions'//TODO read up on import and require difference
/*Lets Make a mock store for testing CRUD Actions*/
var createMockStore = configureMockStore([thunk]); //TODO read up
/*Assertions for actions*/
describe('Actions', () => {
//assert that actions exist check if compiling and imports working
it('should exist', () => {
expect(actions).toExist();
})
describe('Current Supplier', () => {
it('should generate SET_CURR_SUPPLIER action', () => {
var action = {
type: 'SET_CURR_SUPPLIER',
key: 'xkcd234'
}
var res = actions.currSupplier(action.key);
expect(res).toEqual(action);
});
});
describe('Add Supplier', () => {
it('should generate ADD_SUPPLIER action', () => {
var supplier = {
name: 'new supplier',
fact_sheet: 'fact sheet',
liability_sheet: 'liability sheet',
group: 'group',
service_lines: null,
policies: null,
rate_periods: null,
rate_costs: null,
contracts: null,
cancellation_terms: null,
deposit_terms: null,
commission: '22',
creation_date: moment().unix(),
country: 'SA',
region: 'Capetown',
email: 'mail@m.com',
telephone: '2797179',
website: 'ww.ww.ww',
category: 'cat',
rating: '100'
};
var action = {
type: 'ADD_SUPPLIER',
supplier
};
var res = actions.addSupplier(action.supplier);
expect(res).toEqual(action);
});
});
describe('UPDATE SUPPLIER', () => {
var action = {
type:'UPDATE_SUPPLIER',
id: 'xkcd234',
updates: {
region: 'Okavango'
}
};
var res = actions.updateSupplier(action.id, action.updates);
it('should generate UPDATE_SUPPLIER action', () =>{
expect(res).toEqual(action);
});
});
describe('DELETE SUPPLIER', () => {
it('should generate DELETE_SUPPLIER action', () => {
var action = {
type: 'DELETE_SUPPLIER',
key: 1
};
var res = actions.deleteSupplier(action.key);
expect(res).toEqual(action);
});
});
describe('Add Service Line', () => {
it('should generate ADD_SUPPLIER_SERVICE_LINE action', () => {
var sl = {
name: 'luxury room',
category: 'accomodation',
supplier: 'skcd234'
}
var action = {
type: 'ADD_SUPPLIER_SERVICE_LINE',
serviceLine: sl
};
var res = actions.addSupplierServiceLines(action.serviceLine);
expect(res).toEqual(action);
});
});
describe('UPDATE SERVICE LINE', () => {
var action = {
type: 'UPDATE_SERVICE_LINE',
id:1,
updates: {
name: 'lux'
}
};
var res = actions.updateServiceLine(action.id, action.updates);
it('should generate UPDATE_SERVICE_LINE actio', () => {
expect(res).toEqual(action);
});
});
describe('DELETE SERVICE LINE', () => {
it('should generate DELETE_SERVICE_LINE action', () => {
var action = {
type: 'DELETE_SERVICE_LINE',
id: 1
};
var res = actions.deleteServiceLine(action.id);
expect(res).toEqual(action);
});
});
describe('Add Supplier Policy', () => {
it('should generate ADD_SUPPLIER_POLICY action',() => {
var policy = {
supplier:'xkcd234',
name: 'child policy',
text: 'unattended children will be given sugar laden expressos'
};
var action = {
type: 'ADD_SUPPLIER_POLICY',
policy: policy
};
var res = actions.addSupplierPolicy(action.policy);
expect(res).toEqual(action);
});
});
describe('UPDATE policy', () => {
var action = {
type: 'UDPATE_POLICY',
id: 1,
updates: {
name:'cancellation'
}
};
var res = actions.updatePolicy(action.id, action.updates);
it('should generate UPDATE_POLICY acion', () => {
expect(res).toEqual(action);
});
});
describe('DELETE POLICY', () => {
it('should generare DELETE_POLICY action', () => {
var action = {
type: 'DELETE_POLICY',
id: 1
};
var res = actions.deletePolicy(action.id);
expect(res).toEqual(action);
});
});
describe('Add Supplier Rate Period', () => {
it('should generate ADD_SUPPLIER_RATE_PERIOD action', () => {
var rateperiod = {
name:'peak',
start: '01 Jan',
end: '02 Jan',
supplier: 'xkcd234'
};
var action = {
type: 'ADD_SUPPLIER_RATE_PERIOD',
period: rateperiod
};
var res = actions.addSupplierRatePeriod(action.period);
expect(res).toEqual(action);
});
});
describe('UPDATE Rate Period', () => {
var action = {
type: 'UPDATE_RATE_PERIOD',
id: 1,
updates: {
start: '02 Jan'
}
};
var res = actions.updateSupplierRatePeriod(action.id, action.updates);
it('should generate UPDATE_RATE_PERIOD action',() => {
expect(res).toEqual(action);
});
});
describe('DELETE Rate Period', () => {
it('should generate DELETE_RATE_PERIOD action', () => {
var action = {
type: 'DELETE_RATE_PERIOD',
id: 2
};
var res = actions.deleteRatePeriod(action.id);
expect(res).toEqual(action);
});
});
describe('Add Supplier Rate Cost', () => {
it('should generate ADD_SUPPLIER_COSTS action', () => {
var ratecost = {
service_line: 'lux',
rate_period: 'peak',
type: 'pax',
pps: 'pps cost',
single: 'single cost',
thirdadu: 'third adult cost',
child: 'child rate cost'
};
var action = {
type: 'ADD_SUPPLIER_COSTS',
ratecost: ratecost
};
var res = actions.addSupplierCosts(action.ratecost);
expect(res).toEqual(action);
});
});
describe('UPDATE Rate Cost', () => {
it('should generate UPDATE_COST action', () => {
var action = {
type: 'UPDATE_COST',
id: 1,
updates: {
type: 'rack'
}
};
var res = actions.updateSupplierCost(action.id, action.updates);
expect(res).toEqual(action);
});
});
describe('DELETE Rate Cost', () => {
it('should generare delete RATE Cost Action', () => {
var action = {
type: 'DELETE_COST',
id: 2
};
var res = actions.deleteRateCost(action.id);
expect(res).toEqual(action);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment