@@ -11,14 +11,7 @@ governing permissions and limitations under the License.
1111*/
1212
1313const fs = require ( 'fs' )
14- /* eslint-disable no-unused-vars */
15- const path = require ( 'path' )
16- /* eslint-disable no-unused-vars */
17- const chalk = require ( 'chalk' )
18- const fetch = require ( 'node-fetch' )
19- jest . mock ( 'node-fetch' , ( ) => jest . fn ( ) )
2014const auditLogger = require ( '../../../src/lib/audit-logger' )
21- const { getCliEnv } = require ( '@adobe/aio-lib-env' )
2215
2316jest . mock ( 'fs' )
2417jest . mock ( 'chalk' , ( ) => ( {
@@ -41,28 +34,12 @@ const mockLogEvent = {
4134 orgId : 'mockorg'
4235}
4336
44- const mockResponse = Promise . resolve ( {
45- ok : true ,
46- status : 200 ,
47- text : ( ) => {
48- return { }
49- }
50- } )
51-
52- const mockErrorResponse = Promise . resolve ( {
53- ok : false ,
54- status : 400 ,
55- text : ( ) => {
56- return { }
57- }
58- } )
59-
6037beforeEach ( ( ) => {
61- fetch . mockReset ( )
38+ setFetchMock ( true , 200 , { } )
6239} )
6340
6441test ( 'sendAuditLogs with valid params' , async ( ) => {
65- fetch . mockReturnValue ( mockResponse )
42+ setFetchMock ( true , 200 , { } )
6643 const options = {
6744 method : 'POST' ,
6845 headers : {
@@ -78,7 +55,7 @@ test('sendAuditLogs with valid params', async () => {
7855
7956// NOTE: this test is blocked until the audit service is available in prod
8057test ( 'sendAuditLogs with default params' , async ( ) => {
81- fetch . mockReturnValue ( mockResponse )
58+ setFetchMock ( true , 200 , { } )
8259 const options = {
8360 method : 'POST' ,
8461 headers : {
@@ -93,7 +70,7 @@ test('sendAuditLogs with default params', async () => {
9370} )
9471
9572test ( 'should take prod endpoint if calling sendAuditLogs with non-exisiting env' , async ( ) => {
96- fetch . mockReturnValue ( mockResponse )
73+ setFetchMock ( true , 200 , { } )
9774 const options = {
9875 method : 'POST' ,
9976 headers : {
@@ -108,7 +85,7 @@ test('should take prod endpoint if calling sendAuditLogs with non-exisiting env'
10885} )
10986
11087test ( 'sendAuditLogs error response' , async ( ) => {
111- fetch . mockReturnValue ( mockErrorResponse )
88+ setFetchMock ( false , 400 , { } )
11289 const options = {
11390 method : 'POST' ,
11491 headers : {
0 commit comments