Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { OrderService } from './order.service'
- describe('Order maintainence', () => {
- let service: OrderService;
- beforeEach(() => { service = new OrderService(null, null); });
- it('Should add a product to the general list', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.addProduct(product)
- .subscribe(() => {
- expect(service.orderItems).toContain(product)
- })
- }),
- it('Should add a product to the ID list', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.addProduct(product)
- .subscribe(() => {
- expect(service.ids).toContain(product._id)
- })
- }),
- it('Should return true when adding a product to the list', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.addProduct(product)
- .subscribe((result) => {
- expect(result).toBe(true)
- })
- }),
- it('Should return false when adding a product which is already in the list', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.orderItems.push(product);
- service.ids.push(product._id)
- service.addProduct(product)
- .subscribe((result) => {
- expect(result).toBe(false)
- })
- })
- it('Should not add a product when adding a product which is already in the list', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.orderItems.push(product);
- service.ids.push(product._id)
- service.addProduct(product)
- .subscribe(() => {
- expect(service.orderItems.length).toBe(1)
- expect(service.ids.length).toBe(1)
- })
- }),
- it('Should clear the order when clearOrder() is called', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.orderItems.push(product);
- service.ids.push(product._id)
- service.clearOrder()
- expect(service.orderItems).toBeNull
- expect(service.ids).toBeNull
- }),
- it('Should return the order when getOrder() is called', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.orderItems.push(product);
- service.ids.push(product._id)
- service.getOrder()
- .subscribe((result) => {
- expect(result.length).toBe(1)
- })
- }),
- it('Should remove an item removeAt(pos) is called', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- const product2: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.orderItems.push(product);
- service.orderItems.push(product2);
- service.ids.push(product._id);
- service.ids.push(product2._id);
- service.removeAt(1)
- expect(service.orderItems.length).toBe(1)
- expect(service.ids.length).toBe(1)
- }),
- it('Should do nothing when removeAt(pos) is called with a pos that is out of bounds', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.orderItems.push(product);
- service.ids.push(product._id);
- service.removeAt(1)
- expect(service.orderItems.length).toBe(1)
- expect(service.ids.length).toBe(1)
- }),
- it('Should do nothing when removeAt(pos) is called with a negative pos', () => {
- const product: IProduct = {
- name: 'name',
- image: '/imageurl/image.jpg',
- price: 100,
- thumbnail: '/imageurl/thumbnail_image.jpg',
- _id: '_id'
- }
- service.orderItems.push(product);
- service.ids.push(product._id);
- service.removeAt(-1)
- expect(service.orderItems.length).toBe(1)
- expect(service.ids.length).toBe(1)
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement