11import nock from 'nock'
22
33import { version } from '../../package.json'
4- import * as webHelper from '../../src/helpers/web'
4+ import { generateQuery , getPackage , parsePOSTResults , populateBuildParams , uploadToCodecov , uploadToCodecovPUT } from '../../src/helpers/web'
55import { IServiceParams } from '../../src/types'
66
77describe ( 'Web Helpers' , ( ) => {
@@ -33,7 +33,7 @@ describe('Web Helpers', () => {
3333 . query ( true )
3434 . reply ( 200 , 'testPOSTHTTP' )
3535
36- const response = await webHelper . uploadToCodecov (
36+ const response = await uploadToCodecov (
3737 uploadURL ,
3838 token ,
3939 query ,
@@ -56,7 +56,7 @@ describe('Web Helpers', () => {
5656 . query ( true )
5757 . reply ( 200 , 'testPOSTHTTPS' )
5858
59- const response = await webHelper . uploadToCodecov (
59+ const response = await uploadToCodecov (
6060 uploadURL ,
6161 token ,
6262 query ,
@@ -68,9 +68,10 @@ describe('Web Helpers', () => {
6868
6969 it ( 'Can PUT to the storage endpoint' , async ( ) => {
7070 jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
71- uploadURL = 'https://results.codecov.io\nhttps://codecov.io'
72- const response = await webHelper . uploadToCodecovPUT ( uploadURL , uploadFile )
73- expect ( response . resultURL ) . toBe ( 'https://results.codecov.io' )
71+ uploadURL = `https://results.codecov.io
72+ https://codecov.io`
73+ const response = await uploadToCodecovPUT ( uploadURL , uploadFile )
74+ expect ( response . resultURL ) . toEqual ( 'https://results.codecov.io' )
7475 } )
7576
7677 it ( 'Can generate query URL' , ( ) => {
@@ -87,13 +88,13 @@ describe('Web Helpers', () => {
8788 pr : 2 ,
8889 job : '6' ,
8990 }
90- expect ( webHelper . generateQuery ( queryParams ) ) . toBe (
91+ expect ( generateQuery ( queryParams ) ) . toBe (
9192 'branch=testBranch&commit=commitSHA&build=4&build_url=https://ci-providor.local/job/xyz&name=testName&tag=tagV1&slug=testOrg/testRepo&service=testingCI&flags=unit,uploader&pr=2&job=6' ,
9293 )
9394 } )
9495
9596 it ( 'can populateBuildParams() from args' , ( ) => {
96- const result = webHelper . populateBuildParams (
97+ const result = populateBuildParams (
9798 { args : { flags : 'testFlag' , tag : 'testTag' } , environment : { } } ,
9899 {
99100 name : '' ,
@@ -113,7 +114,7 @@ describe('Web Helpers', () => {
113114 } )
114115
115116 it ( 'can populateBuildParams() from args with multiple flags as string' , ( ) => {
116- const result = webHelper . populateBuildParams (
117+ const result = populateBuildParams (
117118 { args : { flags : 'testFlag1,testFlag2' , tag : 'testTag' } , environment : { } } ,
118119 {
119120 name : '' ,
@@ -133,7 +134,7 @@ describe('Web Helpers', () => {
133134 } )
134135
135136 it ( 'can populateBuildParams() from args with multiple flags as list' , ( ) => {
136- const result = webHelper . populateBuildParams (
137+ const result = populateBuildParams (
137138 { args : { flags : [ 'testFlag1' , 'testFlag2' ] , tag : 'testTag' } , environment : { } } ,
138139 {
139140 name : '' ,
@@ -153,12 +154,38 @@ describe('Web Helpers', () => {
153154 } )
154155
155156 it ( 'can getPackage() from source' , ( ) => {
156- const result = webHelper . getPackage ( 'github-actions-2.0.0' )
157+ const result = getPackage ( 'github-actions-2.0.0' )
157158 expect ( result ) . toBe ( `github-actions-2.0.0-uploader-${ version } ` )
158159 } )
159160
160161 it ( 'can getPackage() from no source' , ( ) => {
161- const result = webHelper . getPackage ( '' )
162+ const result = getPackage ( '' )
162163 expect ( result ) . toBe ( `uploader-${ version } ` )
163164 } )
165+
166+ describe ( 'parsePOSTResults()' , ( ) => {
167+ it ( 'will throw when unable to match' , ( ) => {
168+ const testURL = `🤨`
169+ expect ( ( ) => parsePOSTResults ( testURL ) ) . toThrowError ( / P a r s i n g r e s u l t s f r o m P O S T f a i l e d / )
170+ } )
171+
172+ it ( 'will throw when can not match exactly twice' , ( ) => {
173+ const testURL = `dummyURL`
174+ expect ( ( ) => parsePOSTResults ( testURL ) ) . toThrowError ( 'Incorrect number of urls when parsing results from POST: 1' )
175+ } )
176+
177+ it ( 'will return an object when parsing correctly and input has multiple linebreaks' , ( ) => {
178+ const testURL = `dummyURL
179+
180+
181+
182+
183+
184+
185+
186+ OtherURL`
187+ const expectedResults = { putURL : 'OtherURL' , resultURL : 'dummyURL' }
188+ expect ( parsePOSTResults ( testURL ) ) . toEqual ( expectedResults )
189+ } )
190+ } )
164191} )
0 commit comments