Skip to content

Commit

Permalink
added tests for getSwaggerUIRelease
Browse files Browse the repository at this point in the history
  • Loading branch information
Legion2 committed Jul 20, 2022
1 parent ab884d7 commit 89e64d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 21 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as io from '@actions/io';
import {
validateSwaggerUIConfig,
createSwaggerConfig
createSwaggerConfig,
getSwaggerUIRelease,
Config
} from '../src/swagger-ui-action';

test('specFile config mode can be selected', async () => {
Expand Down Expand Up @@ -30,3 +32,21 @@ test('swaggerConfigFile gets copied correctly (#156)', async () => {
await expect(await swaggerConfig).toBe('swagger-config.yaml');
await io.rmRF('/tmp/swagger-config.yaml');
});

test('getSwaggerUIRelease returns without error for latest', async () => {
const swaggerUIVersion = await getSwaggerUIRelease({
swaggerUIVersion: '^3.0.0'
} as Config);
expect(swaggerUIVersion.tag_name).toMatch(/3.*/);
});

test('getSwaggerUIRelease returns specific version', async () => {
const swaggerUIVersion = await getSwaggerUIRelease({
swaggerUIVersion: '3.0.0'
} as Config);
expect(swaggerUIVersion).toMatchObject({
tag_name: 'v3.0.0',
tarball_url:
'https://api.github.com/repos/swagger-api/swagger-ui/tarball/v3.0.0'
});
});
5 changes: 2 additions & 3 deletions src/swagger-ui-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,10 @@ export async function getSwaggerUIRelease({
.filter(x => x.prerelease !== true)
.filter(x => x.draft !== true)
.filter(x => satisfies(x.tag_name, swaggerUIVersion));
if (matchingReleases.length) {
if (matchingReleases.length > 0) {
done();
return matchingReleases;
}
return [];
return matchingReleases;
}
);

Expand Down

0 comments on commit 89e64d5

Please sign in to comment.