Commits

Art Lowel authored de6abb7ce6e
add a responseparser that only looks at the status code, and use it for statistic event responses
No tags

src/app/core/data/status-code-only-response-parsing.service.spec.ts

Added
1 +import { StatusCodeOnlyResponseParsingService } from './status-code-only-response-parsing.service';
2 +
3 +describe('StatusCodeOnlyResponseParsingService', () => {
4 + let service;
5 + let statusCode;
6 + let statusText;
7 +
8 + beforeEach(() => {
9 + service = new StatusCodeOnlyResponseParsingService();
10 + });
11 +
12 + describe('parse', () => {
13 +
14 + describe('when the response is successful', () => {
15 + beforeEach(() => {
16 + statusCode = 201;
17 + statusText = `${statusCode}`;
18 + });
19 +
20 + it('should return a success RestResponse', () => {
21 + const result = service.parse(undefined, {
22 + statusCode,
23 + statusText
24 + });
25 +
26 + expect(result.isSuccessful).toBe(true);
27 + });
28 +
29 + it('should return a RestResponse with the correct status code', () => {
30 + const result = service.parse(undefined, {
31 + statusCode,
32 + statusText
33 + });
34 +
35 + expect(result.statusCode).toBe(statusCode);
36 + });
37 +
38 + it('should return a RestResponse with the correct status text', () => {
39 + const result = service.parse(undefined, {
40 + statusCode,
41 + statusText
42 + });
43 +
44 + expect(result.statusText).toBe(statusText);
45 + });
46 + });
47 +
48 + describe('when the response is unsuccessful', () => {
49 + beforeEach(() => {
50 + statusCode = 400;
51 + statusText = `${statusCode}`;
52 + });
53 +
54 + it('should return an error RestResponse', () => {
55 + const result = service.parse(undefined, {
56 + statusCode,
57 + statusText
58 + });
59 +
60 + expect(result.isSuccessful).toBe(false);
61 + });
62 +
63 + it('should return a RestResponse with the correct status code', () => {
64 + const result = service.parse(undefined, {
65 + statusCode,
66 + statusText
67 + });
68 +
69 + expect(result.statusCode).toBe(statusCode);
70 + });
71 +
72 + it('should return a RestResponse with the correct status text', () => {
73 + const result = service.parse(undefined, {
74 + statusCode,
75 + statusText
76 + });
77 +
78 + expect(result.statusText).toBe(statusText);
79 + });
80 + });
81 + });
82 +});

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut