UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

93 lines (70 loc) 2.82 kB
/** * Copyright Super iPaaS Integration LLC, an IBM Company 2024 */ import {TestManager} from '../../src/index.js'; import path from 'path'; import fs from 'fs'; import {NewmanRunner} from '../../src/newman/newman-test.js'; jest.mock('../../src/service/log-wrapper.js'); jest.mock('@apic/studio-logger', ()=> ({ LoggerConfig: { isLoggerEnabled: jest.fn(), }, })); jest.mock('../../src/newman/newman-test.js'); describe('test manager tests', () => { it('validate the reference function ', async() => { const obj = new TestManager(); const zipFilePath = path.resolve(__dirname, '../assets/valid-asset.zip'); const zipBuffer = fs.readFileSync(zipFilePath); const refmap = await obj['validateReferences'](zipBuffer); expect(refmap).toBe(true); }); it('validate the reference function for incalid reference', async() => { const obj = new TestManager(); const zipFilePath = path.resolve(__dirname, '../assets/invalid-asset.zip'); const zipBuffer = fs.readFileSync(zipFilePath); const refmap = await obj['validateReferences'](zipBuffer); expect(refmap).toBe(false); }); it('testing the validate method', async() => { const obj = new TestManager(); const zipFilePath = path.resolve(__dirname, '../assets/valid-asset-with-$endpoint.zip'); const zipBuffer = fs.readFileSync(zipFilePath); const refmap = await obj['validate'](zipBuffer); expect(refmap).toBe(true); }); it('testing the validate method for invalid asset', async() => { const obj = new TestManager(); const zipFilePath = path.resolve(__dirname, '../assets/invalid-asset.zip'); const zipBuffer = fs.readFileSync(zipFilePath); const refmap =await obj['validate'](zipBuffer); expect(refmap).toBe(false); }); it('testing the validate method for invalid $endpoint', async() => { const obj = new TestManager(); const zipFilePath = path.resolve(__dirname, '../assets/invalid-endpoint-asset.zip'); const zipBuffer = fs.readFileSync(zipFilePath); const refmap =await obj['validate'](zipBuffer); expect(refmap).toBe(false); }); it('should return newman response for valid asset', async() => { (NewmanRunner as jest.Mock).mockImplementation(() => { return { run: () => {return true;}, }; }); const obj = new TestManager(); const zipFilePath = path.resolve(__dirname, '../assets/valid-asset.zip'); const zipBuffer = fs.readFileSync(zipFilePath); const result=await obj.processFile(zipBuffer); expect(result).toEqual([true]); }); it('testing the validate method for invalid Endpoint', async() => { const obj = new TestManager(); const zipFilePath = path.resolve(__dirname, '../assets/invalid-asset-empty-endpoint.zip'); const zipBuffer = fs.readFileSync(zipFilePath); const refmap =await obj['validate'](zipBuffer); expect(refmap).toBe(false); }); });