Skip to content

Commit 499570c

Browse files
committed
test: increase test coverage for generated config
1 parent cec5819 commit 499570c

1 file changed

Lines changed: 169 additions & 12 deletions

File tree

test/generated-config.test.js

Lines changed: 169 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ describe('Generated Config (QuickType)', () => {
8181
sessionMaxAgeHours: 24,
8282
rateLimit: {
8383
windowMs: 60000,
84-
limit: 150
84+
limit: 150,
8585
},
8686
tempPassword: {
8787
sendEmail: false,
88-
emailConfig: {}
88+
emailConfig: {},
8989
},
9090
authorisedList: [
9191
{
@@ -98,7 +98,7 @@ describe('Generated Config (QuickType)', () => {
9898
{
9999
type: 'fs',
100100
params: {
101-
filepath: './.'
101+
filepath: './.',
102102
},
103103
enabled: true,
104104
},
@@ -154,12 +154,8 @@ describe('Generated Config (QuickType)', () => {
154154
{ project: 'proj1', name: 'repo1', url: 'https://github.com/proj1/repo1.git' },
155155
{ project: 'proj2', name: 'repo2', url: 'https://github.com/proj2/repo2.git' },
156156
],
157-
authentication: [
158-
{ type: 'local', enabled: true }
159-
],
160-
sink: [
161-
{ type: 'fs', params: { filepath: './.' }, enabled: true }
162-
],
157+
authentication: [{ type: 'local', enabled: true }],
158+
sink: [{ type: 'fs', params: { filepath: './.' }, enabled: true }],
163159
plugins: ['plugin1', 'plugin2'],
164160
privateOrganizations: ['org1', 'org2'],
165161
};
@@ -185,12 +181,12 @@ describe('Generated Config (QuickType)', () => {
185181
},
186182
rateLimit: {
187183
windowMs: 60000,
188-
limit: 150
184+
limit: 150,
189185
},
190186
tempPassword: {
191187
sendEmail: false,
192-
emailConfig: {}
193-
}
188+
emailConfig: {},
189+
},
194190
};
195191

196192
const result = Convert.toGitProxyConfig(JSON.stringify(configWithNesting));
@@ -200,5 +196,166 @@ describe('Generated Config (QuickType)', () => {
200196
expect(result.rateLimit).to.be.an('object');
201197
expect(result.tempPassword).to.be.an('object');
202198
});
199+
200+
it('should handle complex validation scenarios', () => {
201+
// Test configuration that will trigger more validation paths
202+
const complexConfig = {
203+
proxyUrl: 'https://proxy.example.com',
204+
cookieSecret: 'secret',
205+
authentication: [{ type: 'local', enabled: true }],
206+
sink: [{ type: 'fs', params: { filepath: './.' }, enabled: true }],
207+
208+
api: {
209+
github: {
210+
baseUrl: 'https://api.github.com',
211+
token: 'secret-token',
212+
rateLimit: 100,
213+
enabled: true,
214+
},
215+
},
216+
217+
domains: {
218+
localhost: 'http://localhost:3000',
219+
'example.com': 'https://example.com',
220+
},
221+
222+
// Complex nested structures
223+
attestationConfig: {
224+
enabled: true,
225+
questions: [
226+
{
227+
id: 'q1',
228+
type: 'boolean',
229+
required: true,
230+
label: 'Test Question',
231+
},
232+
],
233+
},
234+
};
235+
236+
const result = Convert.toGitProxyConfig(JSON.stringify(complexConfig));
237+
expect(result).to.be.an('object');
238+
expect(result.api).to.be.an('object');
239+
expect(result.domains).to.be.an('object');
240+
});
241+
242+
it('should handle array validation edge cases', () => {
243+
const configWithArrays = {
244+
proxyUrl: 'https://proxy.example.com',
245+
cookieSecret: 'secret',
246+
authentication: [{ type: 'local', enabled: true }],
247+
sink: [{ type: 'fs', params: { filepath: './.' }, enabled: true }],
248+
249+
// Test different array structures
250+
authorisedList: [
251+
{
252+
project: 'test1',
253+
name: 'repo1',
254+
url: 'https://github.com/test1/repo1.git',
255+
},
256+
{
257+
project: 'test2',
258+
name: 'repo2',
259+
url: 'https://github.com/test2/repo2.git',
260+
},
261+
],
262+
263+
plugins: ['plugin-a', 'plugin-b', 'plugin-c'],
264+
privateOrganizations: ['org1', 'org2'],
265+
};
266+
267+
const result = Convert.toGitProxyConfig(JSON.stringify(configWithArrays));
268+
expect(result.authorisedList).to.have.lengthOf(2);
269+
expect(result.plugins).to.have.lengthOf(3);
270+
expect(result.privateOrganizations).to.have.lengthOf(2);
271+
});
272+
273+
it('should exercise transformation functions with edge cases', () => {
274+
const edgeCaseConfig = {
275+
proxyUrl: 'https://proxy.example.com',
276+
cookieSecret: 'secret',
277+
authentication: [{ type: 'local', enabled: true }],
278+
sink: [{ type: 'fs', params: { filepath: './.' }, enabled: true }],
279+
280+
sessionMaxAgeHours: 0,
281+
csrfProtection: false,
282+
283+
tempPassword: {
284+
sendEmail: true,
285+
emailConfig: {
286+
host: 'smtp.example.com',
287+
port: 587,
288+
secure: false,
289+
auth: {
290+
user: 'user@example.com',
291+
pass: 'password',
292+
},
293+
},
294+
length: 12,
295+
expiry: 7200,
296+
},
297+
298+
rateLimit: {
299+
windowMs: 900000,
300+
limit: 1000,
301+
message: 'Rate limit exceeded',
302+
},
303+
};
304+
305+
const result = Convert.toGitProxyConfig(JSON.stringify(edgeCaseConfig));
306+
expect(result.sessionMaxAgeHours).to.equal(0);
307+
expect(result.csrfProtection).to.equal(false);
308+
expect(result.tempPassword).to.be.an('object');
309+
expect(result.tempPassword.length).to.equal(12);
310+
});
311+
312+
it('should test validation error paths', () => {
313+
try {
314+
// Try to parse something that looks like valid JSON but has wrong structure
315+
Convert.toGitProxyConfig('{"proxyUrl": 123, "authentication": "not-array"}');
316+
} catch (error) {
317+
expect(error).to.be.an('error');
318+
}
319+
});
320+
321+
it('should test date and null handling', () => {
322+
// Test that null values cause validation errors (covers error paths)
323+
const configWithNulls = {
324+
proxyUrl: 'https://proxy.example.com',
325+
cookieSecret: null,
326+
authentication: [{ type: 'local', enabled: true }],
327+
sink: [{ type: 'fs', params: { filepath: './.' }, enabled: true }],
328+
contactEmail: null,
329+
urlShortener: null,
330+
};
331+
332+
expect(() => {
333+
Convert.toGitProxyConfig(JSON.stringify(configWithNulls));
334+
}).to.throw('Invalid value');
335+
});
336+
337+
it('should test serialization back to JSON', () => {
338+
const testConfig = {
339+
proxyUrl: 'https://test.com',
340+
cookieSecret: 'secret',
341+
authentication: [{ type: 'local', enabled: true }],
342+
sink: [{ type: 'fs', params: { filepath: './.' }, enabled: true }],
343+
rateLimit: {
344+
windowMs: 60000,
345+
limit: 150,
346+
},
347+
tempPassword: {
348+
sendEmail: false,
349+
emailConfig: {},
350+
},
351+
};
352+
353+
const parsed = Convert.toGitProxyConfig(JSON.stringify(testConfig));
354+
const serialized = Convert.gitProxyConfigToJson(parsed);
355+
const reparsed = JSON.parse(serialized);
356+
357+
expect(reparsed.proxyUrl).to.equal('https://test.com');
358+
expect(reparsed.rateLimit).to.be.an('object');
359+
});
203360
});
204361
});

0 commit comments

Comments
 (0)