@@ -8,6 +8,7 @@ import { afterEach, before, beforeEach, describe, it } from 'mocha';
88import * as sinon from 'sinon' ;
99import { File , FormData , Response } from 'node-fetch' ;
1010
11+ import { AMO_BASE_URL } from '../../../src/program.js' ;
1112import Client , {
1213 JwtApiAuth ,
1314 saveIdToFile ,
@@ -69,7 +70,7 @@ describe('util.submit-addon', () => {
6970 const signAddonDefaults = {
7071 apiKey : 'some-key' ,
7172 apiSecret : 'ffff' ,
72- amoBaseUrl : 'https://some.url/api/v5' ,
73+ amoBaseUrl : AMO_BASE_URL ,
7374 timeout : 1 ,
7475 downloadDir : '/some-dir/' ,
7576 xpiPath : '/some.xpi' ,
@@ -81,7 +82,7 @@ describe('util.submit-addon', () => {
8182 it ( 'creates Client with parameters' , async ( ) => {
8283 const apiKey = 'fooKey' ;
8384 const apiSecret = '4321' ;
84- const amoBaseUrl = 'https://foo.host/api/v5' ;
85+ const amoBaseUrl = AMO_BASE_URL ;
8586 const baseUrl = new URL ( amoBaseUrl ) ;
8687 const downloadDir = '/foo' ;
8788 const clientSpy = sinon . spy ( Client ) ;
@@ -186,7 +187,7 @@ describe('util.submit-addon', () => {
186187 } ) ;
187188
188189 describe ( 'Client' , ( ) => {
189- const baseUrl = new URL ( 'http://not-a-real-amo-api.com/api/v5' ) ;
190+ const baseUrl = new URL ( AMO_BASE_URL ) ;
190191
191192 const apiAuth = new JwtApiAuth ( {
192193 apiKey : 'fake-api-key' ,
@@ -241,6 +242,22 @@ describe('util.submit-addon', () => {
241242 getAuthHeaderSpy . resetHistory ( ) ;
242243 } ) ;
243244
245+ it ( 'adds a missing trailing slash to baseUrl before setting apiUrl' , ( ) => {
246+ const noSlashBaseUrl = new URL ( 'http://url.without/trailing/slash' ) ;
247+ const client = new Client ( { ...clientDefaults , baseUrl : noSlashBaseUrl } ) ;
248+ assert . equal (
249+ client . apiUrl . href ,
250+ new URL ( `${ noSlashBaseUrl . href } /addons/` ) . href
251+ ) ;
252+ } ) ;
253+
254+ it ( 'drops extra characters on baseUrl before setting apiUrl' , ( ) => {
255+ const cleanUrl = 'http://url.with/extra' ;
256+ const extraBaseUrl = new URL ( `${ cleanUrl } ?#` ) ;
257+ const client = new Client ( { ...clientDefaults , baseUrl : extraBaseUrl } ) ;
258+ assert . equal ( client . apiUrl . href , new URL ( `${ cleanUrl } /addons/` ) . href ) ;
259+ } ) ;
260+
244261 describe ( 'doUploadSubmit' , ( ) => {
245262 it ( 'submits the xpi' , async ( ) => {
246263 const client = new Client ( clientDefaults ) ;
0 commit comments