juice-shop

Форк
0
/
payment.service.spec.ts 
73 строки · 2.6 Кб
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 { PaymentService } from './payment.service'
9

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

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

22
  it('should get payment cards directly from the api', inject([PaymentService, HttpTestingController],
23
    fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
24
      let res
25
      service.get().subscribe((data) => (res = data))
26
      const req = httpMock.expectOne('http://localhost:3000/api/Cards')
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 single payment card directly from the api', inject([PaymentService, HttpTestingController],
36
    fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
37
      let res
38
      service.getById(1).subscribe((data) => (res = data))
39
      const req = httpMock.expectOne('http://localhost:3000/api/Cards/1')
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 create payment card directly from the api', inject([PaymentService, HttpTestingController],
49
    fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
50
      let res
51
      service.save({}).subscribe((data) => (res = data))
52
      const req = httpMock.expectOne('http://localhost:3000/api/Cards/')
53
      req.flush({ data: 'apiResponse' })
54
      tick()
55
      expect(req.request.method).toBe('POST')
56
      expect(res).toBe('apiResponse')
57
      httpMock.verify()
58
    })
59
  ))
60

61
  it('should delete payment card directly from the api', inject([PaymentService, HttpTestingController],
62
    fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
63
      let res
64
      service.del(1).subscribe((data) => (res = data))
65
      const req = httpMock.expectOne('http://localhost:3000/api/Cards/1')
66
      req.flush({ data: 'apiResponse' })
67
      tick()
68
      expect(req.request.method).toBe('DELETE')
69
      expect(res).toBe('apiResponse')
70
      httpMock.verify()
71
    })
72
  ))
73
})
74

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

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

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

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