Skip to content

Commit 7639803

Browse files
committed
added-tests
1 parent a4d6c96 commit 7639803

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

test/integration/generate/fromTemplate.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,55 @@ describe('template', () => {
208208
}
209209
);
210210
});
211+
describe('fetch, httpsproxyagent, and proxyflags', () => {
212+
test
213+
.stdout()
214+
.command([
215+
...generalOptions,
216+
'--output=./test/docs/proxy',
217+
'--force-write',
218+
'--proxyHost=localhost',
219+
'--proxyPort=8080',
220+
nonInteractive
221+
])
222+
.it('should use proxy settings when provided', (ctx, done) => {
223+
expect(ctx.stdout).to.contain('Check out your shiny new generated files at ./test/docs/proxy');
224+
cleanup('./test/docs/proxy');
225+
done();
226+
});
227+
228+
test
229+
.stdout()
230+
.command([
231+
'generate:fromTemplate',
232+
'https://raw.githubusercontent.com/asyncapi/spec/master/examples/2.0.0/streetlights.yml',
233+
'@asyncapi/html-template',
234+
'--output=./test/docs/fetch',
235+
'--force-write',
236+
nonInteractive
237+
])
238+
.it('should fetch remote AsyncAPI file', (ctx, done) => {
239+
expect(ctx.stdout).to.contain('Check out your shiny new generated files at ./test/docs/fetch');
240+
cleanup('./test/docs/fetch');
241+
done();
242+
});
243+
244+
test
245+
.stdout()
246+
.command([
247+
'generate:fromTemplate',
248+
'https://raw.githubusercontent.com/asyncapi/spec/master/examples/2.0.0/streetlights.yml',
249+
'@asyncapi/html-template',
250+
'--output=./test/docs/proxy-fetch',
251+
'--force-write',
252+
'--proxyHost=localhost',
253+
'--proxyPort=8080',
254+
nonInteractive
255+
])
256+
.it('should fetch remote AsyncAPI file using proxy', (ctx, done) => {
257+
expect(ctx.stdout).to.contain('Check out your shiny new generated files at ./test/docs/proxy-fetch');
258+
cleanup('./test/docs/proxy-fetch');
259+
done();
260+
});
261+
});
211262
});

test/integration/generate/models.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { expect, test } from '@oclif/test';
22
import path from 'path';
33
import rimraf from 'rimraf';
44
import { createMockServer, stopMockServer } from '../../helpers';
5+
import { HttpsProxyAgent } from 'https-proxy-agent';
6+
import fetch from 'node-fetch';
57
const generalOptions = ['generate:models'];
68
const outputDir = './test/fixtures/generate/models';
79

@@ -36,6 +38,67 @@ describe('models', () => {
3638
done();
3739
});
3840

41+
describe('proxy-related tests', () => {
42+
test
43+
.stderr()
44+
.stdout()
45+
.env({ PROXY_HOST: '127.0.0.1', PROXY_PORT: '3128' }) // Mock environment variables for proxy
46+
.do(() => {
47+
process.env.PROXY_HOST = '127.0.0.1';
48+
process.env.PROXY_PORT = '3128';
49+
})
50+
.command([...generalOptions, 'typescript', 'http://localhost:8080/dummySpec.yml', '--proxyHost=127.0.0.1', '--proxyPort=3128'])
51+
.it('works with proxy settings', (ctx, done) => {
52+
expect(ctx.stdout).to.contain('Successfully generated the following models: ');
53+
expect(process.env.PROXY_HOST).to.equal('127.0.0.1');
54+
expect(process.env.PROXY_PORT).to.equal('3128');
55+
done();
56+
});
57+
58+
test
59+
.stderr()
60+
.stdout()
61+
.command([...generalOptions, 'typescript', 'http://localhost:8080/dummySpec.yml'])
62+
.it('works without proxy settings', (ctx, done) => {
63+
expect(ctx.stdout).to.contain('Successfully generated the following models: ');
64+
done();
65+
});
66+
});
67+
68+
describe('fetch with proxy and without proxy', () => {
69+
test
70+
.stderr()
71+
.stdout()
72+
.do(() => {
73+
const proxyUrl = 'http://127.0.0.1:3128';
74+
const proxyAgent = new HttpsProxyAgent(proxyUrl);
75+
const customFetch = (url, options = {}) => fetch(url, { ...options, agent: proxyAgent });
76+
77+
customFetch('http://localhost:8080/dummySpec.yml')
78+
.then((response) => {
79+
expect(response.ok).to.be.true;
80+
})
81+
.catch((err) => {
82+
throw new Error(`Failed to fetch with proxy: ${err.message}`);
83+
});
84+
})
85+
.it('tests fetch with proxy agent');
86+
87+
test
88+
.stderr()
89+
.stdout()
90+
.do(() => {
91+
fetch('http://localhost:8080/dummySpec.yml')
92+
.then((response) => {
93+
expect(response.ok).to.be.true;
94+
})
95+
.catch((err) => {
96+
throw new Error(`Failed to fetch without proxy: ${err.message}`);
97+
});
98+
})
99+
.it('tests fetch without proxy agent');
100+
});
101+
39102
describe('with logging diagnostics', () => {
40103
test
41104
.stderr()

0 commit comments

Comments
 (0)