Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /* global beforeEach, test, expect */
  2. const service = require('./service');
  3.  
  4. const events = [
  5. { title: 'Free wine!' },
  6. { title: 'BrainCandyLive' },
  7. ];
  8.  
  9. test('"create" creates event', () => {
  10. const id1 = service.create(events[0]);
  11. expect(id1).toBeDefined();
  12. const id2 = service.create(events[1]);
  13. expect(id2).toBeDefined();
  14. });
  15.  
  16. test('"list" returns all entities', () => {
  17. expect(service.list()).toEqual(events);
  18. });
  19.  
  20. test('"find" returns object for existing id', () => {
  21. expect(service.find(1)).toEqual(events[0]);
  22. });
  23.  
  24. test('"find" throws an exception if non existing id is provided', () => {
  25. expect(() => service.find(-1)).toThrow();
  26. });
  27.  
  28. test('"Update" updates event for exising id', () => {
  29. const updatedEvent = { title: 'Updated' };
  30. service.update(2, updatedEvent);
  31. expect(service.find(2)).toEqual(updatedEvent);
  32. });
  33.  
  34. test('"Update" throws an exception if non existing id is provided', () => {
  35. expect(() => service.update(3, { title: 'Updated' })).toThrow();
  36. });
  37.  
  38. test('"Remove" removes event with existing id', () => {
  39. service.remove(1);
  40. expect(service.list().length).toEqual(1);
  41. });
  42.  
  43. test('"Remove" hrows an exception if non existing id is provided', () => {
  44. expect(() => service.remove(3)).toThrow();
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement