@apistudio/apim-cli
Version:
CLI for API Management Products
93 lines (76 loc) • 2.92 kB
text/typescript
// src/WMGWRuntimeInventory.spec.ts
// Mock the parent class before importing
jest.mock("@apic/smith-inventory", () => {
const mockRuntimeInventory = jest.fn().mockImplementation(() => ({
// Mock methods that would be inherited
getPolicySequenceType: jest.fn().mockReturnValue({
"sequenceTypes":["freeflow"]
}),
extendMasterContent: jest.fn(),
extendSchemaDefinitions: jest.fn(),
extendDefaultVersions: jest.fn()
}));
// Add a prototype to the constructor for instanceof checks
mockRuntimeInventory.prototype = {
getPolicySequenceType: jest.fn(),
extendMasterContent: jest.fn(),
extendSchemaDefinitions: jest.fn(),
extendDefaultVersions: jest.fn()
};
return {
RuntimeInventory: mockRuntimeInventory
};
});
// Import the class under test using require
const { WMGWRuntimeInventory } = require("./wmgw_runtimeinventry");
const { RuntimeInventory } = require("@apic/smith-inventory");
describe('WMGWRuntimeInventory', () => {
let inventoryInstance: any;
beforeEach(() => {
// Clear all mocks before each test
jest.clearAllMocks();
// Create a new instance for each test
inventoryInstance = new WMGWRuntimeInventory();
});
describe('initialization', () => {
it('should create an instance of WMGWRuntimeInventory', () => {
expect(inventoryInstance).toBeInstanceOf(WMGWRuntimeInventory);
});
it('should call the parent constructor', () => {
// Verify the parent constructor was called
expect(RuntimeInventory).toHaveBeenCalledTimes(1);
expect(RuntimeInventory).toHaveBeenCalledWith();
});
});
describe('inheritance', () => {
it('should inherit methods from RuntimeInventory', () => {
// Test that inherited methods exist on the instance
expect(inventoryInstance.getPolicySequenceType).toBeDefined();
});
it('should properly call inherited methods', () => {
// Call an inherited method
inventoryInstance.getPolicySequenceType();
// Verify the method was called
expect(inventoryInstance.getPolicySequenceType).toHaveBeenCalledTimes(1);
});
it('should return expected values from inherited methods', () => {
// Set up the mock return value
const expectedRuntimes = {
"sequenceTypes":["freeflow"]
};
// Call the method
const result = inventoryInstance.getPolicySequenceType();
// Verify the result
expect(result).toEqual(expectedRuntimes);
});
});
// If WMGWRuntimeInventory adds any custom behavior in the future,
// additional tests would be added here
describe('future extensions', () => {
it('is extensible for adding custom behavior', () => {
// This is a placeholder test for future extensions
expect(WMGWRuntimeInventory).toBeDefined();
});
});
});
// Remove any export statements