juice-shop

Форк
0
/
order-history.service.spec.ts 
60 строк · 2.2 Кб
1
/*
2
 * Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3
 * SPDX-License-Identifier: MIT
4
 */
5

6
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
7
import { fakeAsync, inject, TestBed, tick } from '@angular/core/testing'
8
import { OrderHistoryService } from './order-history.service'
9

10
describe('OrderHistoryService', () => {
11
  beforeEach(() => {
12
    TestBed.configureTestingModule({
13
      imports: [HttpClientTestingModule],
14
      providers: [OrderHistoryService]
15
    })
16
  })
17

18
  it('should be created', inject([OrderHistoryService], (service: OrderHistoryService) => {
19
    expect(service).toBeTruthy()
20
  }))
21

22
  it('should get payment cards directly from the api', inject([OrderHistoryService, HttpTestingController],
23
    fakeAsync((service: OrderHistoryService, httpMock: HttpTestingController) => {
24
      let res
25
      service.get().subscribe((data) => (res = data))
26
      const req = httpMock.expectOne('http://localhost:3000/rest/order-history')
27
      req.flush({ data: 'apiResponse' })
28
      tick()
29
      expect(req.request.method).toBe('GET')
30
      expect(res).toBe('apiResponse')
31
      httpMock.verify()
32
    })
33
  ))
34

35
  it('should get payment cards directly from the api', inject([OrderHistoryService, HttpTestingController],
36
    fakeAsync((service: OrderHistoryService, httpMock: HttpTestingController) => {
37
      let res
38
      service.getAll().subscribe((data) => (res = data))
39
      const req = httpMock.expectOne('http://localhost:3000/rest/order-history/orders')
40
      req.flush({ data: 'apiResponse' })
41
      tick()
42
      expect(req.request.method).toBe('GET')
43
      expect(res).toBe('apiResponse')
44
      httpMock.verify()
45
    })
46
  ))
47

48
  it('should update address directly from the api', inject([OrderHistoryService, HttpTestingController],
49
    fakeAsync((service: OrderHistoryService, httpMock: HttpTestingController) => {
50
      let res
51
      service.toggleDeliveryStatus(1, {}).subscribe((data) => (res = data))
52
      const req = httpMock.expectOne('http://localhost:3000/rest/order-history/1/delivery-status')
53
      req.flush({ data: 'apiResponse' })
54
      tick()
55
      expect(req.request.method).toBe('PUT')
56
      expect(res).toBe('apiResponse')
57
      httpMock.verify()
58
    })
59
  ))
60
})
61

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.