juice-shop
73 строки · 2.6 Кб
1/*
2* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3* SPDX-License-Identifier: MIT
4*/
5
6import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
7import { fakeAsync, inject, TestBed, tick } from '@angular/core/testing'
8import { PaymentService } from './payment.service'
9
10describe('PaymentService', () => {
11beforeEach(() => {
12TestBed.configureTestingModule({
13imports: [HttpClientTestingModule],
14providers: [PaymentService]
15})
16})
17
18it('should be created', inject([PaymentService], (service: PaymentService) => {
19expect(service).toBeTruthy()
20}))
21
22it('should get payment cards directly from the api', inject([PaymentService, HttpTestingController],
23fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
24let res
25service.get().subscribe((data) => (res = data))
26const req = httpMock.expectOne('http://localhost:3000/api/Cards')
27req.flush({ data: 'apiResponse' })
28tick()
29expect(req.request.method).toBe('GET')
30expect(res).toBe('apiResponse')
31httpMock.verify()
32})
33))
34
35it('should get single payment card directly from the api', inject([PaymentService, HttpTestingController],
36fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
37let res
38service.getById(1).subscribe((data) => (res = data))
39const req = httpMock.expectOne('http://localhost:3000/api/Cards/1')
40req.flush({ data: 'apiResponse' })
41tick()
42expect(req.request.method).toBe('GET')
43expect(res).toBe('apiResponse')
44httpMock.verify()
45})
46))
47
48it('should create payment card directly from the api', inject([PaymentService, HttpTestingController],
49fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
50let res
51service.save({}).subscribe((data) => (res = data))
52const req = httpMock.expectOne('http://localhost:3000/api/Cards/')
53req.flush({ data: 'apiResponse' })
54tick()
55expect(req.request.method).toBe('POST')
56expect(res).toBe('apiResponse')
57httpMock.verify()
58})
59))
60
61it('should delete payment card directly from the api', inject([PaymentService, HttpTestingController],
62fakeAsync((service: PaymentService, httpMock: HttpTestingController) => {
63let res
64service.del(1).subscribe((data) => (res = data))
65const req = httpMock.expectOne('http://localhost:3000/api/Cards/1')
66req.flush({ data: 'apiResponse' })
67tick()
68expect(req.request.method).toBe('DELETE')
69expect(res).toBe('apiResponse')
70httpMock.verify()
71})
72))
73})
74