juice-shop
52 строки · 1.7 Кб
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'
8
9import { QuantityService } from './quantity.service'
10
11describe('QuantityService', () => {
12beforeEach(() => {
13TestBed.configureTestingModule({
14imports: [HttpClientTestingModule],
15providers: [QuantityService]
16})
17})
18
19it('should be created', inject([QuantityService], (service: QuantityService) => {
20expect(service).toBeTruthy()
21}))
22
23it('should get all quantities directly from the rest api', inject([QuantityService, HttpTestingController],
24fakeAsync((service: QuantityService, httpMock: HttpTestingController) => {
25let res
26service.getAll().subscribe((data) => (res = data))
27const req = httpMock.expectOne('http://localhost:3000/api/Quantitys/')
28req.flush({ data: 'apiResponse' })
29
30tick()
31expect(req.request.method).toBe('GET')
32expect(req.request.params.toString()).toBeFalsy()
33expect(res).toBe('apiResponse')
34httpMock.verify()
35})
36))
37
38it('should change quantity directly via the rest api', inject([QuantityService, HttpTestingController],
39fakeAsync((service: QuantityService, httpMock: HttpTestingController) => {
40let res
41service.put(42, {}).subscribe((data) => (res = data))
42const req = httpMock.expectOne('http://localhost:3000/api/Quantitys/42')
43req.flush({ data: 'apiResponse' })
44
45tick()
46expect(req.request.method).toBe('PUT')
47expect(req.request.body).toEqual({})
48expect(res).toBe('apiResponse')
49httpMock.verify()
50})
51))
52})
53