Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { TestBed, inject, async } from '@angular/core/testing';
- import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
- import { Boleto2Service } from './boleto2.service';
- import { JwtService } from '@app/shared/_services/jwt.service';
- import { ApiService } from '@app/shared/_services/api.service';
- import { BoletoValidatorRequest } from '../model/boletoValidator';
- describe('Service: Boleto2Service', () => {
- let url;
- beforeEach(() => {
- TestBed.configureTestingModule({
- imports: [ HttpClientTestingModule ],
- providers: [ Boleto2Service , ApiService, JwtService ]
- });
- url = 'https://localhost:3000/validar';
- });
- it('should be created', inject([Boleto2Service], (service: Boleto2Service) => {
- expect(service).toBeTruthy();
- }));
- it('should get boleto information', async(
- inject([ HttpTestingController, Boleto2Service, ApiService ],
- (httpMock: HttpTestingController, service: Boleto2Service, api: ApiService) => {
- const mockSuccessResponse = {
- 'codigo': 200,
- 'dados': {
- 'Banco': 'XPTO',
- 'IdValidacao': 'xxxxxxxxx',
- 'IsCartaoCredito': false,
- 'IsConsorcio': false,
- 'LinhaDigitavel': '62390001172100004672843846528412477770000352984',
- 'Validade': '22/01/2019',
- 'Valor': 'R$ 3.529,84'
- },
- 'mensagem': null
- };
- const data: BoletoValidatorRequest = {
- 'LinhaDigitavel': '62390.00117 21000.046728 43846.528412 4 77770000352984',
- 'csrf-token': '70-5E-37-8F-51-8B-61-A0-DF-B3-F8-0B-64-53-22-17-32-19-01-E7-6C-FB-BD-E6-E7-A3-AF-E9-B7-64'
- };
- service.ticketValidator(data).subscribe(result =>
- expect(result).toBe(mockSuccessResponse)
- );
- const requestMock = httpMock.expectOne({
- url: url,
- method: 'POST'
- });
- requestMock.flush(mockSuccessResponse);
- }
- )));
- it('should get error error Internal Server Error', (
- inject([ HttpTestingController, Boleto2Service, ApiService ],
- (httpMock: HttpTestingController, service: Boleto2Service, api: ApiService) => {
- const mockErrorResponse = {
- 'status': 500,
- 'statusText': 'Internal Server Error'
- };
- const data: BoletoValidatorRequest = {
- 'LinhaDigitavel': '62390.00117 21000.046728 43846.528412 4 77770000352984',
- 'csrf-token': '70-5E-37-8F-51-8B-61-A0-DF-B3-F8-0B-64-53-22-17-32-19-01-E7-6C-FB-BD-E6-E7-A3-AF-E9-B7-64'
- };
- service.ticketValidator(data).subscribe(null,
- error => {
- expect(error.status).toEqual(mockErrorResponse.status);
- expect(error.statusText).toEqual(mockErrorResponse.statusText);
- }
- );
- const requestMock = httpMock.expectOne({
- url: url,
- method: 'POST'
- });
- requestMock.flush(null, mockErrorResponse);
- }
- )));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement