juice-shop
37 строк · 1.2 Кб
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 { SecurityAnswerService } from './security-answer.service'
10
11describe('SecurityAnswerService', () => {
12beforeEach(() => {
13TestBed.configureTestingModule({
14imports: [HttpClientTestingModule],
15providers: [SecurityAnswerService]
16})
17})
18
19it('should be created', inject([SecurityAnswerService], (service: SecurityAnswerService) => {
20expect(service).toBeTruthy()
21}))
22
23it('should create feedback directly via the rest api', inject([SecurityAnswerService, HttpTestingController],
24fakeAsync((service: SecurityAnswerService, httpMock: HttpTestingController) => {
25let res: any
26service.save(null).subscribe((data) => (res = data))
27const req = httpMock.expectOne('http://localhost:3000/api/SecurityAnswers/')
28req.flush({ data: 'apiResponse' })
29
30tick()
31expect(req.request.method).toBe('POST')
32expect(req.request.body).toBeFalsy()
33expect(res).toBe('apiResponse')
34httpMock.verify()
35})
36))
37})
38