@@ -10,10 +10,10 @@ import {
1010 getPackage ,
1111 parsePOSTResults ,
1212 populateBuildParams ,
13- uploadToCodecov ,
13+ uploadToCodecovPOST ,
1414 uploadToCodecovPUT ,
1515} from '../../src/helpers/web'
16- import { IServiceParams , UploaderArgs } from '../../src/types'
16+ import { IServiceParams , PostResults , UploaderArgs } from '../../src/types'
1717import { createEmptyArgs } from '../test_helpers'
1818
1919describe ( 'Web Helpers' , ( ) => {
@@ -45,11 +45,17 @@ describe('Web Helpers', () => {
4545 . query ( true )
4646 . reply ( 200 , 'testPOSTHTTP' )
4747
48- const response = await uploadToCodecov ( uploadURL , token , query , source , {
49- flags : '' ,
50- slug : '' ,
51- upstream : '' ,
52- } )
48+ const response = await uploadToCodecovPOST (
49+ new URL ( uploadURL ) ,
50+ token ,
51+ query ,
52+ source ,
53+ {
54+ flags : '' ,
55+ slug : '' ,
56+ upstream : '' ,
57+ } ,
58+ )
5359 try {
5460 expect ( response ) . toBe ( 'testPOSTHTTP' )
5561 } catch ( error ) {
@@ -66,24 +72,32 @@ describe('Web Helpers', () => {
6672 . query ( true )
6773 . reply ( 200 , 'testPOSTHTTPS' )
6874
69- const response = await uploadToCodecov ( uploadURL , token , query , source , {
70- flags : '' ,
71- slug : '' ,
72- upstream : '' ,
73- } )
75+ const response = await uploadToCodecovPOST (
76+ new URL ( uploadURL ) ,
77+ token ,
78+ query ,
79+ source ,
80+ {
81+ flags : '' ,
82+ slug : '' ,
83+ upstream : '' ,
84+ } ,
85+ )
7486 expect ( response ) . toBe ( 'testPOSTHTTPS' )
7587 } )
7688
7789 it ( 'Can PUT to the storage endpoint' , async ( ) => {
7890 jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => void { } )
79- uploadURL = `https://results.codecov.io
80- https://codecov.io`
81- const response = await uploadToCodecovPUT ( uploadURL , uploadFile , {
91+ const postResults : PostResults = {
92+ putURL : new URL ( 'https://codecov.io' ) ,
93+ resultURL : new URL ( 'https://results.codecov.io' ) ,
94+ }
95+ const response = await uploadToCodecovPUT ( postResults , uploadFile , {
8296 flags : '' ,
8397 slug : '' ,
8498 upstream : '' ,
8599 } )
86- expect ( response . resultURL ) . toEqual ( 'https://results.codecov.io' )
100+ expect ( response . resultURL . href ) . toStrictEqual ( 'https://results.codecov.io/ ' )
87101 } )
88102
89103 it ( 'Can generate query URL' , ( ) => {
@@ -234,17 +248,20 @@ describe('Web Helpers', () => {
234248 } )
235249
236250 it ( 'will return an object when parsing correctly and input has multiple linebreaks' , ( ) => {
237- const testURL = `dummyURL
251+ const testURL = `https://result.codecov.local
238252
239253
240254
241255
242256
243257
244258
245- OtherURL`
246- const expectedResults = { putURL : 'OtherURL' , resultURL : 'dummyURL' }
247- expect ( parsePOSTResults ( testURL ) ) . toEqual ( expectedResults )
259+ https://put.codecov.local`
260+ const expectedResults = {
261+ putURL : 'https://put.codecov.local/' ,
262+ resultURL : 'https://result.codecov.local/' ,
263+ }
264+ expect ( JSON . stringify ( parsePOSTResults ( testURL ) ) ) . toStrictEqual ( JSON . stringify ( expectedResults ) )
248265 } )
249266 } )
250267} )
@@ -263,15 +280,15 @@ describe('generateRequestHeadersPOST()', () => {
263280 it ( 'should return return the correct url when args.upstream is not set' , ( ) => {
264281 args . upstream = ''
265282 const requestHeaders = generateRequestHeadersPOST (
266- 'https:localhost.local' ,
283+ new URL ( 'https:// localhost.local' ) ,
267284 '134' ,
268285 'slug=testOrg/testUploader' ,
269286 'G' ,
270287 args ,
271288 )
272289
273- expect ( requestHeaders . url ) . toEqual (
274- `https:localhost.local/upload/v4?package=${ getPackage (
290+ expect ( requestHeaders . url . href ) . toEqual (
291+ `https:// localhost.local/upload/v4?package=${ getPackage (
275292 'G' ,
276293 ) } &token=134&slug=testOrg/testUploader`,
277294 )
@@ -282,15 +299,15 @@ describe('generateRequestHeadersPOST()', () => {
282299 it ( 'should return return the correct url when args.upstream is set' , ( ) => {
283300 args . upstream = 'http://proxy.local'
284301 const requestHeaders = generateRequestHeadersPOST (
285- 'https:localhost.local' ,
302+ new URL ( 'https:localhost.local' ) ,
286303 '134' ,
287304 'slug=testOrg/testUploader' ,
288305 'G' ,
289306 args ,
290307 )
291308
292- expect ( requestHeaders . url ) . toEqual (
293- `https:localhost.local/upload/v4?package=${ getPackage (
309+ expect ( requestHeaders . url . href ) . toEqual (
310+ `https:// localhost.local/upload/v4?package=${ getPackage (
294311 'G' ,
295312 ) } &token=134&slug=testOrg/testUploader`,
296313 )
@@ -308,25 +325,25 @@ describe('generateRequestHeadersPUT()', () => {
308325 it ( 'should return return the correct url when args.upstream is not set' , ( ) => {
309326 args . upstream = ''
310327 const requestHeaders = generateRequestHeadersPUT (
311- 'https:localhost.local' ,
328+ new URL ( 'https:// localhost.local' ) ,
312329 "I'm a coverage report!" ,
313330 args ,
314331 )
315332
316- expect ( requestHeaders . url ) . toEqual ( 'https:localhost.local' )
333+ expect ( requestHeaders . url . href ) . toEqual ( 'https:// localhost.local/ ' )
317334 expect ( requestHeaders . options . body ) . toEqual ( "I'm a coverage report!" )
318335 expect ( typeof requestHeaders . options . agent ) . toEqual ( 'undefined' )
319336 } )
320337
321338 it ( 'should return return the correct url when args.upstream is set' , ( ) => {
322339 args . upstream = 'http://proxy.local'
323340 const requestHeaders = generateRequestHeadersPUT (
324- 'https:localhost.local' ,
341+ new URL ( 'https:// localhost.local' ) ,
325342 "I'm a coverage report!" ,
326343 args ,
327344 )
328345
329- expect ( requestHeaders . url ) . toEqual ( 'https:localhost.local' )
346+ expect ( requestHeaders . url . href ) . toEqual ( 'https:// localhost.local/ ' )
330347 expect ( requestHeaders . options . body ) . toEqual ( "I'm a coverage report!" )
331348 expect ( requestHeaders . options . agent ) . toMatchObject (
332349 new HttpsProxyAgent ( args . upstream ) ,
0 commit comments