@@ -11,8 +11,11 @@ const LedSignFunctions =
1111 require ( '../../client/ledsign/led_sign_client' ) ;
1212const LoggingFunctions = require ( '../../client/util/logging-helpers' ) ;
1313const sinon = require ( 'sinon' ) ;
14+ const SceApiTester = require ( '../util/SceApiTester' ) ;
15+ const { response } = require ( 'express' ) ;
1416
1517let app = null ;
18+ let test = null ;
1619const expect = chai . expect ;
1720
1821chai . should ( ) ;
@@ -68,6 +71,7 @@ describe('LedSign', () => {
6871
6972 before ( done => {
7073 app = tools . initializeServer ( __dirname + '/../../client/api/LedSign.js' ) ;
74+ test = new SceApiTester ( app ) ;
7175 done ( ) ;
7276 } ) ;
7377
@@ -86,20 +90,14 @@ describe('LedSign', () => {
8690 } ) ;
8791
8892 describe ( '/POST healthCheck' , ( ) => {
93+ const officer = 'thai' ;
8994 let signResponse = null ;
90- it ( 'Should return statusCode 200 when the sign is up' , done => {
95+ it ( 'Should return statusCode 200 when the sign is up' , async ( ) => {
9196 healthCheckMock . resolves ( SUCCESS_MESSAGE ) ;
92- chai
93- . request ( app )
94- . post ( '/SceRpcApi/LedSign/healthCheck' )
95- . then ( function ( res ) {
96- signResponse = res . body ;
97- expect ( res ) . to . have . status ( OK ) ;
98- done ( ) ;
99- } )
100- . catch ( err => {
101- throw err ;
102- } ) ;
97+ const response = await test . sendPostRequest (
98+ '/SceRpcApi/LedSign/healthCheck' , officer ) ;
99+ expect ( response ) . to . have . status ( OK ) ;
100+ signResponse = response . body ;
103101 } ) ;
104102 it ( 'Should return the correct values when modified' , done => {
105103 healthCheckMock . resolves ( SUCCESS_MESSAGE ) ;
@@ -112,65 +110,37 @@ describe('LedSign', () => {
112110 expect ( signResponse . borderColor ) . to . equal ( VALID_SIGN_REQUEST . borderColor ) ;
113111 done ( ) ;
114112 } ) ;
115- it ( 'Should return statusCode 404 when the sign is down' , done => {
113+ it ( 'Should return statusCode 404 when the sign is down' , async ( ) => {
116114 healthCheckMock . resolves ( false ) ;
117- chai
118- . request ( app )
119- . post ( '/SceRpcApi/LedSign/healthCheck' )
120- . then ( function ( res ) {
121- expect ( res ) . to . have . status ( NOT_FOUND ) ;
122- done ( ) ;
123- } )
124- . catch ( err => {
125- throw err ;
126- } ) ;
115+ const response = await test . sendPostRequest (
116+ '/SceRpcApi/LedSign/healthCheck' , officer ) ;
117+ expect ( response ) . to . have . status ( NOT_FOUND ) ;
127118 } ) ;
128119 } ) ;
129120
130121 describe ( '/POST updateSignText' , ( ) => {
131- it ( 'Should return statusCode 200 when the sign text is updated' , done => {
132- addSignLogStub . resolves ( SUCCESS_MESSAGE ) ;
133- updateSignTextMock . resolves ( SUCCESS_MESSAGE ) ;
134- chai
135- . request ( app )
136- . post ( '/SceRpcApi/LedSign/updateSignText' )
137- . send ( VALID_SIGN_REQUEST )
138- . then ( function ( res ) {
139- expect ( res ) . to . have . status ( OK ) ;
140- done ( ) ;
141- } )
142- . catch ( err => {
143- throw err ;
144- } ) ;
145- } ) ;
146- it ( 'Should return statusCode 404 when the sign is down' , done => {
122+ it ( 'Should return statusCode 200 when the sign text is updated' ,
123+ async ( ) => {
124+ addSignLogStub . resolves ( SUCCESS_MESSAGE ) ;
125+ updateSignTextMock . resolves ( SUCCESS_MESSAGE ) ;
126+ const response = await test . sendPostRequest (
127+ '/SceRpcApi/LedSign/updateSignText' , VALID_SIGN_REQUEST ) ;
128+ expect ( response ) . to . have . status ( OK ) ;
129+ } ) ;
130+ it ( 'Should return statusCode 404 when the sign is down' , async ( ) => {
147131 addSignLogStub . resolves ( SUCCESS_MESSAGE ) ;
148132 updateSignTextMock . rejects ( ERROR_MESSAGE ) ;
149- chai
150- . request ( app )
151- . post ( '/SceRpcApi/LedSign/updateSignText' )
152- . then ( function ( res ) {
153- expect ( res ) . to . have . status ( NOT_FOUND ) ;
154- done ( ) ;
155- } )
156- . catch ( err => {
157- throw err ;
158- } ) ;
133+ const response = await test . sendPostRequest (
134+ '/SceRpcApi/LedSign/updateSignText' , INVALID_SIGN_REQUEST ) ;
135+ expect ( response ) . to . have . status ( NOT_FOUND ) ;
159136 } ) ;
160137 it ( 'Should return statuscode 400 when we can\'t log sign activity' ,
161- done => {
138+ async ( ) => {
162139 addSignLogStub . resolves ( ERROR_MESSAGE ) ;
163140 updateSignTextMock . rejects ( ERROR_MESSAGE ) ;
164- chai
165- . request ( app )
166- . post ( '/SceRpcApi/LedSign/updateSignText' )
167- . then ( function ( res ) {
168- expect ( res ) . to . have . status ( BAD_REQUEST ) ;
169- done ( ) ;
170- } )
171- . catch ( err => {
172- throw err ;
173- } ) ;
141+ const response = await test . sendPostRequest (
142+ '/SceRpcApi/LedSign/updateSignText' , { } ) ;
143+ expect ( response ) . to . have . status ( BAD_REQUEST ) ;
174144 } ) ;
175145 } ) ;
176146} ) ;
0 commit comments