Skip to content

Commit

Permalink
Merge pull request #99 from BenPatterson2/init-bug
Browse files Browse the repository at this point in the history
BUG: code meant to be defaulting to the prod url but is throwing error
  • Loading branch information
Avalara-ChrisWalker authored Nov 19, 2019
2 parents 9f4ffaf + dc6bf2b commit d994cd8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/AvaTaxClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export default class AvaTaxClient {
this.baseUrl = 'https://rest.avatax.com';
if (environment == 'sandbox') {
this.baseUrl = 'https://sandbox-rest.avatax.com';
} else if (
environment.substring(0, 8) == 'https://' ||
environment.substring(0, 7) == 'http://'
) {
} else if ( /^(https:\/\/|http:\/\/)/.test(environment) ) {
this.baseUrl = environment;
}
this.clientId =
Expand Down
21 changes: 21 additions & 0 deletions test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,26 @@ describe('Avatax Client', () => {
// expect(client.licenseKey).toBe(licenseKey);
// todo: verify base64 computed header from accountId + licenseKey
});

it('should handle various environment settings', () => {

const testCases = [
{ environment:'sandbox', expected: 'https://sandbox-rest.avatax.com' },
{ environment:'production', expected: 'https://rest.avatax.com' },
{ environment: undefined, expected: 'https://rest.avatax.com' },
{ environment:'http://specific-url' , expected: 'http://specific-url' },
{ environment:'https://specific-https-url' , expected: 'https://specific-https-url' },
]
testCases.forEach(({ environment, expected })=>{

const client = new Avatax({
appName:'myapp',
appVersion:'1.0',
machineName: 'test-run',
environment
})
expect(client.baseUrl).toBe(expected);
})
});
});

0 comments on commit d994cd8

Please sign in to comment.