@apistudio/apim-cli
Version:
CLI for API Management Products
133 lines (116 loc) • 3.42 kB
JavaScript
/**
* Copyright IBM Corp. 2024, 2025
*/
describe('APICAssetInfo', () => {
it('should create an APICAssetInfo object with required properties', () => {
const fileInfo = {
isModified: false,
path: '/path/to/file',
fileUrl: 'https://example.com/file',
orgId: 'org123',
};
const assetInfo = {
name: 'Test Asset',
nameSpace: 'test-namespace',
version: '1.0.0',
fileInfo,
kind: 'api',
};
expect(assetInfo.name).toBe('Test Asset');
expect(assetInfo.nameSpace).toBe('test-namespace');
expect(assetInfo.version).toBe('1.0.0');
expect(assetInfo.fileInfo).toEqual(fileInfo);
expect(assetInfo.kind).toBe('api');
expect(assetInfo.description).toBeUndefined();
expect(assetInfo.tags).toBeUndefined();
expect(assetInfo.content).toBeUndefined();
});
it('should create an APICAssetInfo object with optional properties', () => {
const fileInfo = {
isModified: true,
path: '/path/to/file',
fileUrl: 'https://example.com/file',
orgId: 'org123',
};
const assetInfo = {
name: 'Test Asset',
nameSpace: 'test-namespace',
version: '1.0.0',
fileInfo,
kind: 'api',
description: 'Test description',
tags: ['tag1', 'tag2'],
content: { key: 'value' },
};
expect(assetInfo.description).toBe('Test description');
expect(assetInfo.tags).toEqual(['tag1', 'tag2']);
expect(assetInfo.content).toEqual({ key: 'value' });
});
it('should accept string content', () => {
const fileInfo = {
isModified: false,
path: '/path/to/file',
fileUrl: 'https://example.com/file',
orgId: 'org123',
};
const assetInfo = {
name: 'Test Asset',
nameSpace: 'test-namespace',
version: '1.0.0',
fileInfo,
kind: 'api',
content: 'string content',
};
expect(assetInfo.content).toBe('string content');
});
});
describe('OperationWithAPICAssetInfo', () => {
it('should create an OperationWithAPICAssetInfo object with operations', () => {
const fileInfo = {
isModified: false,
path: '/path/to/file',
fileUrl: 'https://example.com/file',
orgId: 'org123',
};
const operations = [
{
path: '/users',
method: 'get',
},
{
path: '/users/{id}',
method: 'post',
},
];
const operationAssetInfo = {
name: 'Test Asset',
nameSpace: 'test-namespace',
version: '1.0.0',
fileInfo,
kind: 'api',
operations,
};
expect(operationAssetInfo.name).toBe('Test Asset');
expect(operationAssetInfo.operations).toEqual(operations);
expect(operationAssetInfo.operations.length).toBe(2);
expect(operationAssetInfo.operations[0].path).toBe('/users');
expect(operationAssetInfo.operations[1].method).toBe('post');
});
it('should create an OperationWithAPICAssetInfo object without operations', () => {
const fileInfo = {
isModified: false,
path: '/path/to/file',
fileUrl: 'https://example.com/file',
orgId: 'org123',
};
const operationAssetInfo = {
name: 'Test Asset',
nameSpace: 'test-namespace',
version: '1.0.0',
fileInfo,
kind: 'api',
};
expect(operationAssetInfo.name).toBe('Test Asset');
expect(operationAssetInfo.operations).toBeUndefined();
});
});