@@ -5,95 +5,95 @@ import { createFakeResponseBody } from '@spec/fakes/common/response';
55import * as TableDataClientModule from '../../common/data/table-data/table-data-client/table-data-client' ;
66
77describe ( 'CrashesApiClient' , ( ) => {
8- let sut : CrashesApiClient ;
8+ let sut : CrashesApiClient ;
99
10- let apiClient ;
11- let apiClientResponse ;
12- let database ;
13- let fakeFormData ;
14- let id ;
15- let pageData ;
16- let rows ;
17- let tableDataClient ;
18- let tableDataClientResponse ;
19- let Comments ;
20- let IpAddress ;
10+ let apiClient ;
11+ let apiClientResponse ;
12+ let database ;
13+ let fakeFormData ;
14+ let id ;
15+ let pageData ;
16+ let rows ;
17+ let tableDataClient ;
18+ let tableDataClientResponse ;
19+ let Comments ;
20+ let IpAddress ;
2121
22- beforeEach ( ( ) => {
23- fakeFormData = createFakeFormData ( ) ;
24- apiClientResponse = createFakeResponseBody ( 200 ) ;
25- apiClient = createFakeBugSplatApiClient ( fakeFormData , apiClientResponse ) ;
22+ beforeEach ( ( ) => {
23+ fakeFormData = createFakeFormData ( ) ;
24+ apiClientResponse = createFakeResponseBody ( 200 ) ;
25+ apiClient = createFakeBugSplatApiClient ( fakeFormData , apiClientResponse ) ;
2626
27- id = 9001 ;
28- database = '☕️' ;
29- Comments = 'it\'s over 9000!' ;
30- IpAddress = '🏡' ;
31- pageData = { coffee : 'black rifle' } ;
32- rows = [ { id, Comments, IpAddress } ] ;
33- tableDataClientResponse = createFakeResponseBody ( 200 , { pageData, rows } ) ;
34- tableDataClient = jasmine . createSpyObj ( 'TableDataClient' , [ 'postGetData' ] ) ;
35- tableDataClient . postGetData . and . resolveTo ( tableDataClientResponse ) ;
36- spyOn ( TableDataClientModule , 'TableDataClient' ) . and . returnValue ( tableDataClient ) ;
27+ id = 9001 ;
28+ database = '☕️' ;
29+ Comments = 'it\'s over 9000!' ;
30+ IpAddress = '🏡' ;
31+ pageData = { coffee : 'black rifle' } ;
32+ rows = [ { id, Comments, IpAddress } ] ;
33+ tableDataClientResponse = createFakeResponseBody ( 200 , { pageData, rows } ) ;
34+ tableDataClient = jasmine . createSpyObj ( 'TableDataClient' , [ 'postGetData' ] ) ;
35+ tableDataClient . postGetData . and . resolveTo ( tableDataClientResponse ) ;
36+ spyOn ( TableDataClientModule , 'TableDataClient' ) . and . returnValue ( tableDataClient ) ;
3737
38- sut = new CrashesApiClient ( apiClient ) ;
39- } ) ;
38+ sut = new CrashesApiClient ( apiClient ) ;
39+ } ) ;
4040
41- describe ( 'getCrashes' , ( ) => {
42- let result ;
43- let request ;
41+ describe ( 'getCrashes' , ( ) => {
42+ let result ;
43+ let request ;
4444
45- beforeEach ( async ( ) => {
46- request = { database } ;
47- result = await sut . getCrashes ( request ) ;
48- } ) ;
45+ beforeEach ( async ( ) => {
46+ request = { database } ;
47+ result = await sut . getCrashes ( request ) ;
48+ } ) ;
4949
50- it ( 'should call postGetData with request' , ( ) => {
51- expect ( tableDataClient . postGetData ) . toHaveBeenCalledWith ( request ) ;
52- } ) ;
50+ it ( 'should call postGetData with request' , ( ) => {
51+ expect ( tableDataClient . postGetData ) . toHaveBeenCalledWith ( request ) ;
52+ } ) ;
5353
54- it ( 'should return value with Comments and IpAddress values mapped to lower-case' , ( ) => {
55- expect ( result . pageData ) . toEqual ( pageData ) ;
56- expect ( result . rows [ 0 ] . id ) . toEqual ( id ) ;
57- expect ( result . rows [ 0 ] . comments ) . toEqual ( Comments ) ;
58- expect ( result . rows [ 0 ] . ipAddress ) . toEqual ( IpAddress ) ;
59- } ) ;
54+ it ( 'should return value with Comments and IpAddress values mapped to lower-case' , ( ) => {
55+ expect ( result . pageData ) . toEqual ( pageData ) ;
56+ expect ( result . rows [ 0 ] . id ) . toEqual ( id ) ;
57+ expect ( result . rows [ 0 ] . comments ) . toEqual ( Comments ) ;
58+ expect ( result . rows [ 0 ] . ipAddress ) . toEqual ( IpAddress ) ;
6059 } ) ;
60+ } ) ;
6161
62- describe ( 'postNotes' , ( ) => {
63- let result ;
64- let notes ;
62+ describe ( 'postNotes' , ( ) => {
63+ let result ;
64+ let notes ;
6565
66- beforeEach ( async ( ) => {
67- notes = 'bulletproof coffee' ;
68- result = await sut . postNotes ( database , id , notes ) ;
69- } ) ;
66+ beforeEach ( async ( ) => {
67+ notes = 'bulletproof coffee' ;
68+ result = await sut . postNotes ( database , id , notes ) ;
69+ } ) ;
7070
71- it ( 'should append, update true, database, id, and Comments to formData' , ( ) => {
72- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'update' , 'true' ) ;
73- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
74- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'id' , `${ id } ` ) ;
75- expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'Comments ' , notes ) ;
76- } ) ;
71+ it ( 'should append, update true, database, id, and Comments to formData' , ( ) => {
72+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'update' , 'true' ) ;
73+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'database' , database ) ;
74+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'id' , `${ id } ` ) ;
75+ expect ( fakeFormData . append ) . toHaveBeenCalledWith ( 'notes ' , notes ) ;
76+ } ) ;
7777
78- it ( 'should call fetch with correct route' , ( ) => {
79- expect ( apiClient . fetch ) . toHaveBeenCalledWith ( '/browse/allcrash .php' , jasmine . anything ( ) ) ;
80- } ) ;
78+ it ( 'should call fetch with correct route' , ( ) => {
79+ expect ( apiClient . fetch ) . toHaveBeenCalledWith ( '/api/crash/notes .php' , jasmine . anything ( ) ) ;
80+ } ) ;
8181
82- it ( 'should call fetch with requestInit containing formData' , ( ) => {
83- expect ( apiClient . fetch ) . toHaveBeenCalledWith (
84- jasmine . anything ( ) ,
85- jasmine . objectContaining ( {
86- method : 'POST' ,
87- body : fakeFormData ,
88- cache : 'no-cache' ,
89- credentials : 'include' ,
90- redirect : 'follow'
91- } )
92- ) ;
93- } ) ;
82+ it ( 'should call fetch with requestInit containing formData' , ( ) => {
83+ expect ( apiClient . fetch ) . toHaveBeenCalledWith (
84+ jasmine . anything ( ) ,
85+ jasmine . objectContaining ( {
86+ method : 'POST' ,
87+ body : fakeFormData ,
88+ cache : 'no-cache' ,
89+ credentials : 'include' ,
90+ redirect : 'follow' ,
91+ } )
92+ ) ;
93+ } ) ;
9494
95- it ( 'should return result' , ( ) => {
96- expect ( result ) . toEqual ( apiClientResponse ) ;
97- } ) ;
95+ it ( 'should return result' , ( ) => {
96+ expect ( result ) . toEqual ( apiClientResponse ) ;
9897 } ) ;
99- } ) ;
98+ } ) ;
99+ } ) ;
0 commit comments