-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates Power Automate commands to use new API endpoint. Closes #5715
- Loading branch information
1 parent
1c23854
commit 9860c95
Showing
31 changed files
with
241 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import assert from 'assert'; | ||
import sinon from 'sinon'; | ||
import auth, { CloudType } from '../../Auth.js'; | ||
import { CommandError } from '../../Command.js'; | ||
import { telemetry } from '../../telemetry.js'; | ||
import PowerAutomateCommand from './PowerAutomateCommand.js'; | ||
|
||
class MockCommand extends PowerAutomateCommand { | ||
public get name(): string { | ||
return 'mock'; | ||
} | ||
|
||
public get description(): string { | ||
return 'Mock command'; | ||
} | ||
|
||
public async commandAction(): Promise<void> { | ||
} | ||
|
||
public commandHelp(): void { | ||
} | ||
} | ||
|
||
describe('PowerAutomateCommand', () => { | ||
const cmd = new MockCommand(); | ||
const cloudError = new CommandError(`Power Automate commands only support the public cloud at the moment. We'll add support for other clouds in the future. Sorry for the inconvenience.`); | ||
|
||
before(() => { | ||
sinon.stub(telemetry, 'trackEvent').returns(); | ||
}); | ||
|
||
after(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('returns correct resource', () => { | ||
const command = new MockCommand(); | ||
assert.strictEqual((command as any).resource, 'https://api.flow.microsoft.com'); | ||
}); | ||
|
||
it(`doesn't throw error when not connected`, () => { | ||
auth.service.connected = false; | ||
(cmd as any).initAction({ options: {} }, {}); | ||
}); | ||
|
||
it('throws error when connected to USGov cloud', () => { | ||
auth.service.connected = true; | ||
auth.service.cloudType = CloudType.USGov; | ||
assert.throws(() => (cmd as any).initAction({ options: {} }, {}), cloudError); | ||
}); | ||
|
||
it('throws error when connected to USGovHigh cloud', () => { | ||
auth.service.connected = true; | ||
auth.service.cloudType = CloudType.USGovHigh; | ||
assert.throws(() => (cmd as any).initAction({ options: {} }, {}), cloudError); | ||
}); | ||
|
||
it('throws error when connected to USGovDoD cloud', () => { | ||
auth.service.connected = true; | ||
auth.service.cloudType = CloudType.USGovDoD; | ||
assert.throws(() => (cmd as any).initAction({ options: {} }, {}), cloudError); | ||
}); | ||
|
||
it('throws error when connected to China cloud', () => { | ||
auth.service.connected = true; | ||
auth.service.cloudType = CloudType.China; | ||
assert.throws(() => (cmd as any).initAction({ options: {} }, {}), cloudError); | ||
}); | ||
|
||
it(`doesn't throw error when connected to public cloud`, () => { | ||
auth.service.connected = true; | ||
auth.service.cloudType = CloudType.Public; | ||
assert.doesNotThrow(() => (cmd as any).initAction({ options: {} }, {})); | ||
}); | ||
}); |
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,22 @@ | ||
import auth, { CloudType } from '../../Auth.js'; | ||
import { Logger } from '../../cli/Logger.js'; | ||
import Command, { CommandArgs, CommandError } from '../../Command.js'; | ||
|
||
export default abstract class PowerAutomateCommand extends Command { | ||
protected get resource(): string { | ||
return 'https://api.flow.microsoft.com'; | ||
} | ||
|
||
protected initAction(args: CommandArgs, logger: Logger): void { | ||
super.initAction(args, logger); | ||
|
||
if (!auth.service.connected) { | ||
// we fail no login in the base command command class | ||
return; | ||
} | ||
|
||
if (auth.service.cloudType !== CloudType.Public) { | ||
throw new CommandError(`Power Automate commands only support the public cloud at the moment. We'll add support for other clouds in the future. Sorry for the inconvenience.`); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.