Skip to content

Commit 3b2742b

Browse files
committed
imtourl test fix
1 parent e9297da commit 3b2742b

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

packages/ingest/tests/helpers.test.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,11 @@ describe('helpers', () => {
395395
*/
396396
const im = {
397397
url: '/path',
398-
headers: { host: 'example.com' }
398+
headers: { host: 'example.com' },
399+
socket: { encrypted: false }
399400
} as unknown as IM;
400401
const url = imToURL(im);
401-
expect(url.href).to.equal('https://example.com/path');
402+
expect(url.href).to.equal('http://example.com/path');
402403
});
403404

404405
/**
@@ -410,11 +411,12 @@ describe('helpers', () => {
410411
url: '/test',
411412
headers: {
412413
host: 'example.com',
413-
'x-forwarded-proto': 'http'
414-
}
414+
'x-forwarded-proto': 'https'
415+
},
416+
socket: { encrypted: false }
415417
} as unknown as IM;
416418
const url = imToURL(im);
417-
expect(url.protocol).to.equal('http:');
419+
expect(url.protocol).to.equal('https:');
418420
});
419421

420422
/**
@@ -427,7 +429,8 @@ describe('helpers', () => {
427429
headers: {
428430
host: 'example.com',
429431
'x-forwarded-proto': ['http', 'https']
430-
}
432+
},
433+
socket: { encrypted: false }
431434
} as unknown as IM;
432435
const url = imToURL(im);
433436
expect(url.protocol).to.equal('http:');
@@ -443,7 +446,21 @@ describe('helpers', () => {
443446
headers: {
444447
host: 'example.com',
445448
'x-forwarded-proto': 'http, https'
446-
}
449+
},
450+
socket: { encrypted: false }
451+
} as unknown as IM;
452+
const url = imToURL(im);
453+
expect(url.protocol).to.equal('http:');
454+
});
455+
456+
it('should handle x-forwarded-proto vs socket', () => {
457+
const im = {
458+
url: '/test',
459+
headers: {
460+
host: 'example.com',
461+
'x-forwarded-proto': 'http'
462+
},
463+
socket: { encrypted: true }
447464
} as unknown as IM;
448465
const url = imToURL(im);
449466
expect(url.protocol).to.equal('http:');
@@ -456,10 +473,11 @@ describe('helpers', () => {
456473
it('should handle invalid URLs with unknownhost', () => {
457474
const im = {
458475
url: 'invalid-url',
459-
headers: { host: undefined }
460-
};
461-
const url = imToURL(im as IM);
462-
expect(url.href).to.equal('https://undefinedinvalid-url/');
476+
headers: { host: undefined },
477+
socket: { encrypted: false }
478+
} as unknown as IM;
479+
const url = imToURL(im);
480+
expect(url.href).to.equal('http://undefinedinvalid-url/');
463481
});
464482
});
465483

@@ -471,9 +489,10 @@ describe('helpers', () => {
471489
it('should convert IM URL query to object', () => {
472490
const im = {
473491
url: '/path?foo=bar&baz=qux',
474-
headers: { host: 'example.com' }
475-
};
476-
const query = imQueryToObject(im as IM);
492+
headers: { host: 'example.com' },
493+
socket: { encrypted: false }
494+
} as unknown as IM;
495+
const query = imQueryToObject(im);
477496
expect(query).to.deep.equal({
478497
foo: 'bar',
479498
baz: 'qux'
@@ -483,9 +502,10 @@ describe('helpers', () => {
483502
it('should handle URL without query parameters', () => {
484503
const im = {
485504
url: '/path',
486-
headers: { host: 'example.com' }
487-
};
488-
const query = imQueryToObject(im as IM);
505+
headers: { host: 'example.com' },
506+
socket: { encrypted: false }
507+
} as unknown as IM;
508+
const query = imQueryToObject(im);
489509
expect(query).to.deep.equal({});
490510
});
491511
});

0 commit comments

Comments
 (0)