-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: w-8612427 load project, if available, to establish loginurl
- Loading branch information
1 parent
3e85ed3
commit 2f3907a
Showing
5 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { SfdcUrl, SfdxProject } from '@salesforce/core'; | ||
import sinon = require('sinon'); | ||
import { expect } from '@salesforce/command/lib/test'; | ||
import { restoreContext, testSetup } from '@salesforce/core/lib/testSetup'; | ||
import { Common } from '../src/common'; | ||
|
||
describe('common unit tests', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const $$ = testSetup(); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-explicit-any | ||
let projectPath: any; | ||
beforeEach(async () => { | ||
projectPath = await $$.localPathRetriever($$.id); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
SfdxProject.instances.clear(); | ||
}); | ||
afterEach(() => { | ||
restoreContext($$); | ||
sandbox.restore(); | ||
}); | ||
describe('production url', () => { | ||
it('should return production URL if not in a dx project', async () => { | ||
sandbox.stub(SfdxProject, 'resolve').throwsException(); | ||
const loginUrl = await Common.getLoginUrl(undefined); | ||
expect(loginUrl).to.equal(SfdcUrl.PRODUCTION); | ||
expect(projectPath).to.be.ok; | ||
}); | ||
it('should return production URL if project with property sfdcLoginUrl absent', async () => { | ||
sandbox.stub(SfdxProject.prototype, 'resolveProjectConfig').resolves({ | ||
packageDirectories: [ | ||
{ | ||
path: 'force-app', | ||
default: true, | ||
}, | ||
], | ||
sourceApiVersion: '50.0', | ||
}); | ||
const loginUrl = await Common.getLoginUrl(undefined); | ||
expect(loginUrl).to.equal(SfdcUrl.PRODUCTION); | ||
}); | ||
it('should return production URL if project with property sfdcLoginUrl present', async () => { | ||
sandbox.stub(SfdxProject.prototype, 'resolveProjectConfig').resolves({ | ||
packageDirectories: [ | ||
{ | ||
path: 'force-app', | ||
default: true, | ||
}, | ||
], | ||
sfdcLoginUrl: SfdcUrl.PRODUCTION, | ||
sourceApiVersion: '50.0', | ||
}); | ||
const loginUrl = await Common.getLoginUrl(undefined); | ||
expect(loginUrl).to.equal(SfdcUrl.PRODUCTION); | ||
}); | ||
}); | ||
describe('custom login url', () => { | ||
const INSTANCE_URL_1 = 'https://example.com'; | ||
const INSTANCE_URL_2 = 'https://some.other.com'; | ||
|
||
it('should return custom login URL if not in a dx project and instanceurl given', async () => { | ||
sandbox.stub(SfdxProject, 'resolve').throwsException(); | ||
const loginUrl = await Common.getLoginUrl(INSTANCE_URL_1); | ||
expect(loginUrl).to.equal(INSTANCE_URL_1); | ||
}); | ||
it('should return custom login URL if project with property sfdcLoginUrl absent and instanceurl given', async () => { | ||
sandbox.stub(SfdxProject.prototype, 'resolveProjectConfig').resolves({ | ||
packageDirectories: [ | ||
{ | ||
path: 'force-app', | ||
default: true, | ||
}, | ||
], | ||
sourceApiVersion: '50.0', | ||
}); | ||
const loginUrl = await Common.getLoginUrl(INSTANCE_URL_1); | ||
expect(loginUrl).to.equal(INSTANCE_URL_1); | ||
}); | ||
it('should return custom login URL if project with property sfdcLoginUrl present and not equal to production URL', async () => { | ||
sandbox.stub(SfdxProject.prototype, 'resolveProjectConfig').resolves({ | ||
packageDirectories: [ | ||
{ | ||
path: 'force-app', | ||
default: true, | ||
}, | ||
], | ||
sfdcLoginUrl: INSTANCE_URL_2, | ||
sourceApiVersion: '50.0', | ||
}); | ||
const loginUrl = await Common.getLoginUrl(undefined); | ||
expect(loginUrl).to.equal(INSTANCE_URL_2); | ||
}); | ||
it('should return custom login URL 1 if project with property sfdcLoginUrl equal to ciustom url 2', async () => { | ||
sandbox.stub(SfdxProject.prototype, 'resolveProjectConfig').resolves({ | ||
packageDirectories: [ | ||
{ | ||
path: 'force-app', | ||
default: true, | ||
}, | ||
], | ||
sfdcLoginUrl: INSTANCE_URL_2, | ||
sourceApiVersion: '50.0', | ||
}); | ||
const loginUrl = await Common.getLoginUrl(INSTANCE_URL_1); | ||
expect(loginUrl).to.equal(INSTANCE_URL_1); | ||
}); | ||
}); | ||
}); |