Skip to content

Commit 6b3506f

Browse files
committed
adding tests to cover changes
1 parent f5d2cd2 commit 6b3506f

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

tests/unit/lib/resource-path.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,20 @@ describe('parseArtifactChangePath', () => {
367367

368368
expect(result).toBeUndefined();
369369
});
370+
371+
it('should return undefined for a path with no extension on the specification file', () => {
372+
const filePath = path.join(baseDir, 'apis', 'my-api', 'specification');
373+
const result = parseArtifactChangePath(baseDir, filePath);
374+
375+
expect(result).toBeUndefined();
376+
});
377+
378+
it('should return undefined for a deeply nested path that does not match any pattern', () => {
379+
const filePath = path.join(baseDir, 'apis', 'my-api', 'extra', 'specification.yaml');
380+
const result = parseArtifactChangePath(baseDir, filePath);
381+
382+
expect(result).toBeUndefined();
383+
});
370384
});
371385

372386
describe('buildArtifactFilePath + parseArtifactPath roundtrip', () => {

tests/unit/services/api-publisher.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,35 @@ describe('api-publisher', () => {
766766
expect(totalTasks).toBe(2);
767767
});
768768

769+
it('should still re-publish explicitly named schemas in incremental mode after spec import', async () => {
770+
const client = createMockClient();
771+
// 'my-explicit-schema' is not a 24-char hex ID so it must be re-published
772+
const children = [
773+
{ type: ResourceType.ApiSchema, nameParts: ['petstore', 'my-explicit-schema'] },
774+
{ type: ResourceType.ApiSchema, nameParts: ['petstore', '69f15c3c10a45d29d855583a'] },
775+
];
776+
const store = createMockStore(children);
777+
store.readResource.mockImplementation(async (_dir: string, descriptor: ResourceDescriptor) => {
778+
if (descriptor.type === ResourceType.Api) {
779+
return { name: 'petstore', properties: { path: 'petstore' } };
780+
}
781+
return null;
782+
});
783+
store.readContent.mockResolvedValue({ content: 'openapi: "3.0.0"', format: 'yaml' });
784+
785+
const apiDescriptor: ResourceDescriptor = { type: ResourceType.Api, nameParts: ['petstore'] };
786+
const incrementalConfig: PublishConfig = { ...testConfig, commitId: 'abc123' };
787+
788+
await publishApi(client, store, testContext, apiDescriptor, incrementalConfig);
789+
790+
// Only the explicit schema should be published (auto-generated hex ID is skipped)
791+
const totalTasks = mockRunParallel.mock.calls.reduce((sum, call) => {
792+
const tasks = call[0] as unknown[];
793+
return sum + tasks.length;
794+
}, 0);
795+
expect(totalTasks).toBe(1);
796+
});
797+
769798
it('should not re-publish schema-reference operations in incremental mode after spec import', async () => {
770799
const client = createMockClient();
771800
const children = [
@@ -891,6 +920,20 @@ describe('api-publisher', () => {
891920
expect(totalTasks).toBe(3);
892921
});
893922

923+
it('should return skipped when root API resource file does not exist', async () => {
924+
const client = createMockClient();
925+
const store = createMockStore([]);
926+
store.readResource.mockResolvedValue(null);
927+
store.readContent.mockResolvedValue({ content: 'openapi: "3.0.0"', format: 'yaml' });
928+
929+
const apiDescriptor: ResourceDescriptor = { type: ResourceType.Api, nameParts: ['missing-api'] };
930+
931+
const result = await publishApi(client, store, testContext, apiDescriptor, testConfig);
932+
933+
expect(result.status).toBe('skipped');
934+
expect(client.putResource).not.toHaveBeenCalled();
935+
});
936+
894937
it('should not inject spec for GraphQL format', async () => {
895938
const client = createMockClient();
896939
const children = [

0 commit comments

Comments
 (0)