juice-shop
51 строка · 1.8 Кб
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 { SecurityQuestionService } from './security-question.service'10
11describe('SecurityQuestionService', () => {12beforeEach(() => {13TestBed.configureTestingModule({14imports: [HttpClientTestingModule],15providers: [SecurityQuestionService]16})17})18
19it('should be created', inject([SecurityQuestionService], (service: SecurityQuestionService) => {20expect(service).toBeTruthy()21}))22
23it('should get all challenges directly from the rest api', inject([SecurityQuestionService, HttpTestingController],24fakeAsync((service: SecurityQuestionService, httpMock: HttpTestingController) => {25let res: any26service.find(null).subscribe((data) => (res = data))27const req = httpMock.expectOne('http://localhost:3000/api/SecurityQuestions/')28req.flush({ data: 'apiResponse' })29tick()30
31expect(req.request.method).toBe('GET')32expect(req.request.params.toString()).toBeFalsy()33expect(res).toBe('apiResponse')34httpMock.verify()35})36))37
38it('should get security question by user email directly from the rest api', inject([SecurityQuestionService, HttpTestingController],39fakeAsync((service: SecurityQuestionService, httpMock: HttpTestingController) => {40let res: any41service.findBy('x@y.z').subscribe((data) => (res = data))42const req = httpMock.expectOne('http://localhost:3000/rest/user/security-question?email=x@y.z')43req.flush({ question: 'apiResponse' })44tick()45
46expect(req.request.method).toBe('GET')47expect(res).toBe('apiResponse')48httpMock.verify()49})50))51})52