Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. import { OrderService } from './order.service'
  2.  
  3. describe('Order maintainence', () => {
  4. let service: OrderService;
  5. beforeEach(() => { service = new OrderService(null, null); });
  6.  
  7. it('Should add a product to the general list', () => {
  8. const product: IProduct = {
  9. name: 'name',
  10. image: '/imageurl/image.jpg',
  11. price: 100,
  12. thumbnail: '/imageurl/thumbnail_image.jpg',
  13. _id: '_id'
  14. }
  15.  
  16. service.addProduct(product)
  17. .subscribe(() => {
  18. expect(service.orderItems).toContain(product)
  19. })
  20. }),
  21.  
  22. it('Should add a product to the ID list', () => {
  23. const product: IProduct = {
  24. name: 'name',
  25. image: '/imageurl/image.jpg',
  26. price: 100,
  27. thumbnail: '/imageurl/thumbnail_image.jpg',
  28. _id: '_id'
  29. }
  30.  
  31. service.addProduct(product)
  32. .subscribe(() => {
  33. expect(service.ids).toContain(product._id)
  34. })
  35. }),
  36.  
  37. it('Should return true when adding a product to the list', () => {
  38. const product: IProduct = {
  39. name: 'name',
  40. image: '/imageurl/image.jpg',
  41. price: 100,
  42. thumbnail: '/imageurl/thumbnail_image.jpg',
  43. _id: '_id'
  44. }
  45.  
  46. service.addProduct(product)
  47. .subscribe((result) => {
  48. expect(result).toBe(true)
  49. })
  50. }),
  51.  
  52. it('Should return false when adding a product which is already in the list', () => {
  53. const product: IProduct = {
  54. name: 'name',
  55. image: '/imageurl/image.jpg',
  56. price: 100,
  57. thumbnail: '/imageurl/thumbnail_image.jpg',
  58. _id: '_id'
  59. }
  60.  
  61. service.orderItems.push(product);
  62. service.ids.push(product._id)
  63.  
  64. service.addProduct(product)
  65. .subscribe((result) => {
  66. expect(result).toBe(false)
  67. })
  68. })
  69.  
  70. it('Should not add a product when adding a product which is already in the list', () => {
  71. const product: IProduct = {
  72. name: 'name',
  73. image: '/imageurl/image.jpg',
  74. price: 100,
  75. thumbnail: '/imageurl/thumbnail_image.jpg',
  76. _id: '_id'
  77. }
  78.  
  79. service.orderItems.push(product);
  80. service.ids.push(product._id)
  81.  
  82. service.addProduct(product)
  83. .subscribe(() => {
  84. expect(service.orderItems.length).toBe(1)
  85. expect(service.ids.length).toBe(1)
  86. })
  87. }),
  88.  
  89. it('Should clear the order when clearOrder() is called', () => {
  90. const product: IProduct = {
  91. name: 'name',
  92. image: '/imageurl/image.jpg',
  93. price: 100,
  94. thumbnail: '/imageurl/thumbnail_image.jpg',
  95. _id: '_id'
  96. }
  97.  
  98. service.orderItems.push(product);
  99. service.ids.push(product._id)
  100. service.clearOrder()
  101.  
  102. expect(service.orderItems).toBeNull
  103. expect(service.ids).toBeNull
  104. }),
  105.  
  106. it('Should return the order when getOrder() is called', () => {
  107. const product: IProduct = {
  108. name: 'name',
  109. image: '/imageurl/image.jpg',
  110. price: 100,
  111. thumbnail: '/imageurl/thumbnail_image.jpg',
  112. _id: '_id'
  113. }
  114.  
  115. service.orderItems.push(product);
  116. service.ids.push(product._id)
  117. service.getOrder()
  118. .subscribe((result) => {
  119. expect(result.length).toBe(1)
  120. })
  121. }),
  122.  
  123. it('Should remove an item removeAt(pos) is called', () => {
  124. const product: IProduct = {
  125. name: 'name',
  126. image: '/imageurl/image.jpg',
  127. price: 100,
  128. thumbnail: '/imageurl/thumbnail_image.jpg',
  129. _id: '_id'
  130. }
  131.  
  132. const product2: IProduct = {
  133. name: 'name',
  134. image: '/imageurl/image.jpg',
  135. price: 100,
  136. thumbnail: '/imageurl/thumbnail_image.jpg',
  137. _id: '_id'
  138. }
  139.  
  140. service.orderItems.push(product);
  141. service.orderItems.push(product2);
  142. service.ids.push(product._id);
  143. service.ids.push(product2._id);
  144. service.removeAt(1)
  145.  
  146. expect(service.orderItems.length).toBe(1)
  147. expect(service.ids.length).toBe(1)
  148. }),
  149.  
  150. it('Should do nothing when removeAt(pos) is called with a pos that is out of bounds', () => {
  151. const product: IProduct = {
  152. name: 'name',
  153. image: '/imageurl/image.jpg',
  154. price: 100,
  155. thumbnail: '/imageurl/thumbnail_image.jpg',
  156. _id: '_id'
  157. }
  158.  
  159. service.orderItems.push(product);
  160. service.ids.push(product._id);
  161. service.removeAt(1)
  162.  
  163. expect(service.orderItems.length).toBe(1)
  164. expect(service.ids.length).toBe(1)
  165. }),
  166.  
  167. it('Should do nothing when removeAt(pos) is called with a negative pos', () => {
  168. const product: IProduct = {
  169. name: 'name',
  170. image: '/imageurl/image.jpg',
  171. price: 100,
  172. thumbnail: '/imageurl/thumbnail_image.jpg',
  173. _id: '_id'
  174. }
  175.  
  176. service.orderItems.push(product);
  177. service.ids.push(product._id);
  178. service.removeAt(-1)
  179.  
  180. expect(service.orderItems.length).toBe(1)
  181. expect(service.ids.length).toBe(1)
  182. })
  183. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement