Skip to content

Commit 2c032cd

Browse files
committed
chore: introduce jest tests
1 parent 46eef17 commit 2c032cd

10 files changed

+404
-0
lines changed

Diff for: jest.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
collectCoverage: true
6+
};

Diff for: src/airport.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe('Airport', () => {
2+
// API currently out of order
3+
test('API', () => {
4+
5+
});
6+
});

Diff for: src/atc.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ATC } from './index';
2+
3+
describe('ATC', () => {
4+
test('should return an ATC response', async () => {
5+
await expect(ATC.get('vatsim'))
6+
.resolves.toMatchObject(expect.any(Array));
7+
});
8+
9+
describe('error handling', () => {
10+
test('should require a valid source', async () => {
11+
await expect(ATC.get('')).rejects.toThrow('No source provided');
12+
});
13+
});
14+
});

Diff for: src/atis.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Atis } from './index';
2+
3+
describe('ATIS', () => {
4+
test('should return an ATIS response', async () => {
5+
const res = await Atis.get('KJFK');
6+
console.log(res);
7+
8+
expect(res.icao).toEqual('KJFK');
9+
expect(res.source).toEqual('FAA');
10+
});
11+
12+
test('should allow selection of sources', async () => {
13+
const res = await Atis.get('KJFK', 'FAA');
14+
console.log(res);
15+
16+
expect(res.icao).toEqual('KJFK');
17+
expect(res.source).toEqual('FAA');
18+
});
19+
20+
describe('error handling', () => {
21+
test('should require an ICAO', async () => {
22+
await expect(Atis.get('')).rejects.toThrow('No ICAO provided');
23+
});
24+
25+
test('should 404 on unknown ICAOs', async () => {
26+
await expect(Atis.get('NONEXISTING')).rejects.toThrow('Request failed with status code 404');
27+
});
28+
});
29+
});

Diff for: src/charts.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Charts } from './index';
2+
3+
describe('Charts', () => {
4+
test('should return a charts response', async () => {
5+
await expect(Charts.get('KJFK')).resolves.toMatchObject({
6+
icao: 'KJFK',
7+
});
8+
});
9+
10+
describe('error handling', () => {
11+
test('should require an ICAO', async () => {
12+
await expect(Charts.get('')).rejects.toThrow('No ICAO provided');
13+
});
14+
});
15+
});

Diff for: src/git-versions.spec.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { GitVersions } from './index';
2+
3+
describe('GitVersions', () => {
4+
describe('Get newest commit', () => {
5+
test('should return return newest commit', async () => {
6+
await expect(GitVersions.getNewestCommit('flybywiresim', 'a32nx', 'master'))
7+
.resolves.toMatchObject({
8+
sha: expect.any(String),
9+
shortSha: expect.any(String),
10+
timestamp: expect.any(Date),
11+
});
12+
});
13+
14+
test('should require all arguments', async () => {
15+
await expect(GitVersions.getNewestCommit('', '', ''))
16+
.rejects.toThrow('Missing argument');
17+
});
18+
});
19+
20+
describe('Get releases', () => {
21+
test('should return return all releases', async () => {
22+
await expect(GitVersions.getReleases('flybywiresim', 'a32nx'))
23+
.resolves.toEqual(expect.arrayContaining([
24+
expect.objectContaining({
25+
name: expect.any(String),
26+
publishedAt: expect.any(Date),
27+
htmlUrl: expect.any(String),
28+
body: expect.any(String),
29+
}),
30+
]));
31+
});
32+
33+
test('should require all arguments', async () => {
34+
await expect(GitVersions.getReleases('', ''))
35+
.rejects.toThrow('Missing argument');
36+
});
37+
});
38+
39+
describe('Get pulls', () => {
40+
test('should return return all pulls', async () => {
41+
await expect(GitVersions.getPulls('flybywiresim', 'a32nx'))
42+
.resolves.toEqual(expect.arrayContaining([
43+
expect.objectContaining({
44+
number: expect.any(Number),
45+
title: expect.any(String),
46+
author: expect.any(String),
47+
labels: expect.any(Array),
48+
isDraft: expect.any(Boolean),
49+
}),
50+
]));
51+
});
52+
53+
test('should require all arguments', async () => {
54+
await expect(GitVersions.getPulls('', ''))
55+
.rejects.toThrow('Missing argument');
56+
});
57+
});
58+
59+
describe('Get artifact', () => {
60+
test('should return return an artifact for a PR', async () => {
61+
await expect(GitVersions.getArtifact('flybywiresim', 'a32nx', '1'))
62+
.resolves.toMatchObject({ artifactUrl: '' });
63+
});
64+
65+
test('should require all arguments', async () => {
66+
await expect(GitVersions.getArtifact('', '', ''))
67+
.rejects.toThrow('Missing argument');
68+
});
69+
});
70+
});

Diff for: src/gnss.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { GNSS } from './index';
2+
3+
describe('GNSS', () => {
4+
test('should return a GNSS response array', async () => {
5+
await expect(GNSS.get()).resolves.toMatchObject(expect.any(Array));
6+
});
7+
});

Diff for: src/metar.spec.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Metar } from './index';
2+
3+
describe('METAR', () => {
4+
test('should return a METAR response', async () => {
5+
const res = await Metar.get('KJFK');
6+
console.log(res);
7+
8+
expect(res.icao).toEqual('KJFK');
9+
expect(res.source).toEqual('Vatsim');
10+
expect(res.metar).not.toEqual('');
11+
});
12+
13+
test('should allow selection of sources', async () => {
14+
const res = await Metar.get('KJFK', 'MS');
15+
console.log(res);
16+
17+
expect(res.icao).toEqual('KJFK');
18+
expect(res.source).toEqual('MS');
19+
expect(res.metar).not.toEqual('');
20+
});
21+
22+
describe('error handling', () => {
23+
test('should require an ICAO', async () => {
24+
await expect(Metar.get('')).rejects.toThrow('No ICAO provided');
25+
});
26+
27+
test('should 404 on unknown ICAOs', async () => {
28+
await expect(Metar.get('NONEXISTING')).rejects.toThrow('Request failed with status code 404');
29+
});
30+
});
31+
});

Diff for: src/taf.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Taf } from './index';
2+
3+
describe('TAF', () => {
4+
test('should return a TAF response', async () => {
5+
const res = await Taf.get('KJFK');
6+
console.log(res);
7+
8+
expect(res.icao).toEqual('KJFK');
9+
expect(res.source).toEqual('AviationWeather');
10+
});
11+
12+
test('should allow selection of sources', async () => {
13+
const res = await Taf.get('KJFK', 'FAA');
14+
console.log(res);
15+
16+
expect(res.icao).toEqual('KJFK');
17+
expect(res.source).toEqual('FAA');
18+
});
19+
20+
describe('error handling', () => {
21+
test('should require an ICAO', async () => {
22+
await expect(Taf.get('')).rejects.toThrow('No ICAO provided');
23+
});
24+
25+
test('should 404 on unknown ICAOs', async () => {
26+
await expect(Taf.get('NONEXISTING')).rejects.toThrow('Request failed with status code 404');
27+
});
28+
});
29+
});

0 commit comments

Comments
 (0)