forked from pnp/cli-microsoft365
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
515b009
commit ca23553
Showing
3 changed files
with
131 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,11 @@ m365 teams user app remove [options] | |
`--id <id>` | ||
: The unique id of the app instance installed for the user. | ||
|
||
`--userId <userId>` | ||
: The ID of the user to uninstall the app for. | ||
`--userId [userId]` | ||
: The ID of the user to uninstall the app for. Specify `userId` or `userName` but not both. | ||
|
||
`--userName [userName]` | ||
: The UPN of the user to uninstall the app for. Specify `userId` or `userName` but not both. | ||
|
||
`-f, --force` | ||
: Confirm removal of app for user. | ||
|
@@ -38,6 +41,12 @@ Uninstall an app for the specified user. | |
m365 teams user app remove --id YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY= --userId 2609af39-7775-4f94-a3dc-0dd67657e900 | ||
``` | ||
|
||
Uninstall an app for the specified user using its UPN. | ||
|
||
```sh | ||
m365 teams user app remove --id YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY= --userName [email protected] | ||
``` | ||
|
||
## Response | ||
|
||
The command won't return a response on success. |
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 |
---|---|---|
|
@@ -7,13 +7,17 @@ import { Logger } from '../../../../cli/Logger.js'; | |
import { CommandError } from '../../../../Command.js'; | ||
import request from '../../../../request.js'; | ||
import { telemetry } from '../../../../telemetry.js'; | ||
import { formatting } from '../../../../utils/formatting.js'; | ||
import { pid } from '../../../../utils/pid.js'; | ||
import { session } from '../../../../utils/session.js'; | ||
import { sinonUtil } from '../../../../utils/sinonUtil.js'; | ||
import commands from '../../commands.js'; | ||
import command from './user-app-remove.js'; | ||
|
||
describe(commands.USER_APP_REMOVE, () => { | ||
const userId = '15d7a78e-fd77-4599-97a5-dbb6372846c6'; | ||
const userName = '[email protected]'; | ||
const appId = 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY='; | ||
let log: string[]; | ||
let logger: Logger; | ||
let promptOptions: any; | ||
|
@@ -72,7 +76,35 @@ describe(commands.USER_APP_REMOVE, () => { | |
const actual = await command.validate({ | ||
options: { | ||
userId: 'invalid', | ||
id: 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=' | ||
id: appId | ||
} | ||
}, commandInfo); | ||
assert.notStrictEqual(actual, true); | ||
}); | ||
|
||
it('fails validation if both userId and userName are not provided.', async () => { | ||
const actual = await command.validate({ | ||
options: { | ||
} | ||
}, commandInfo); | ||
assert.notStrictEqual(actual, true); | ||
}); | ||
|
||
it('fails validation if the userName is not a valid UPN.', async () => { | ||
const actual = await command.validate({ | ||
options: { | ||
userName: "no-an-email", | ||
id: appId | ||
} | ||
}, commandInfo); | ||
assert.notStrictEqual(actual, true); | ||
}); | ||
|
||
it('fails validation if the both userId and userName are provided.', async () => { | ||
const actual = await command.validate({ | ||
options: { | ||
userId: userId, | ||
userName: userName | ||
} | ||
}, commandInfo); | ||
assert.notStrictEqual(actual, true); | ||
|
@@ -81,8 +113,18 @@ describe(commands.USER_APP_REMOVE, () => { | |
it('passes validation when the input is correct', async () => { | ||
const actual = await command.validate({ | ||
options: { | ||
id: 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=', | ||
userId: '15d7a78e-fd77-4599-97a5-dbb6372846c5' | ||
id: appId, | ||
userId: userId | ||
} | ||
}, commandInfo); | ||
assert.strictEqual(actual, true); | ||
}); | ||
|
||
it('passes validation when the input is correct (userName)', async () => { | ||
const actual = await command.validate({ | ||
options: { | ||
id: appId, | ||
userName: userName | ||
} | ||
}, commandInfo); | ||
assert.strictEqual(actual, true); | ||
|
@@ -91,8 +133,8 @@ describe(commands.USER_APP_REMOVE, () => { | |
it('prompts before removing the app when confirmation argument is not passed', async () => { | ||
await command.action(logger, { | ||
options: { | ||
userId: 'c527a470-a882-481c-981c-ee6efaba85c7', | ||
id: 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=' | ||
userId: userId, | ||
id: appId | ||
} | ||
} as any); | ||
let promptIssued = false; | ||
|
@@ -107,25 +149,25 @@ describe(commands.USER_APP_REMOVE, () => { | |
|
||
await command.action(logger, { | ||
options: { | ||
userId: 'c527a470-a882-481c-981c-ee6efaba85c7', | ||
id: 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=' | ||
userId: userId, | ||
id: appId | ||
} | ||
} as any); | ||
assert(requestDeleteSpy.notCalled); | ||
}); | ||
|
||
it('removes the app for the specified user when confirmation is specified (debug)', async () => { | ||
sinon.stub(request, 'delete').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/users/c527a470-a882-481c-981c-ee6efaba85c7/teamwork/installedApps/YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=`) > -1) { | ||
if ((opts.url as string).indexOf(`/users/${userId}/teamwork/installedApps/${appId}`) > -1) { | ||
return; | ||
} | ||
throw 'Invalid request'; | ||
}); | ||
|
||
await command.action(logger, { | ||
options: { | ||
userId: 'c527a470-a882-481c-981c-ee6efaba85c7', | ||
id: 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=', | ||
userId: userId, | ||
id: appId, | ||
debug: true, | ||
force: true | ||
} | ||
|
@@ -134,7 +176,7 @@ describe(commands.USER_APP_REMOVE, () => { | |
|
||
it('removes the app for the specified user when prompt is confirmed (debug)', async () => { | ||
sinon.stub(request, 'delete').callsFake((opts) => { | ||
if ((opts.url as string).indexOf(`/users/c527a470-a882-481c-981c-ee6efaba85c7/teamwork/installedApps/YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=`) > -1) { | ||
if ((opts.url as string).indexOf(`/users/${userId}/teamwork/installedApps/${appId}`) > -1) { | ||
return Promise.resolve(); | ||
} | ||
throw 'Invalid request'; | ||
|
@@ -145,8 +187,33 @@ describe(commands.USER_APP_REMOVE, () => { | |
|
||
await command.action(logger, { | ||
options: { | ||
userId: 'c527a470-a882-481c-981c-ee6efaba85c7', | ||
id: 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=', | ||
userId: userId, | ||
id: appId, | ||
debug: true | ||
} | ||
} as any); | ||
}); | ||
|
||
it('removes the app for the specified user using username', async () => { | ||
sinon.stub(request, 'delete').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/users/${userId}/teamwork/installedApps/${appId}`) > -1) { | ||
return Promise.resolve(); | ||
} | ||
|
||
if ((opts.url as string).indexOf(`/users/${formatting.encodeQueryParameter(userName)}/id`) > -1) { | ||
return { "value": userId }; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); | ||
|
||
sinonUtil.restore(Cli.prompt); | ||
sinon.stub(Cli, 'prompt').resolves({ continue: true }); | ||
|
||
await command.action(logger, { | ||
options: { | ||
userName: userName, | ||
id: appId, | ||
debug: true | ||
} | ||
} as any); | ||
|
@@ -166,16 +233,16 @@ describe(commands.USER_APP_REMOVE, () => { | |
}; | ||
|
||
sinon.stub(request, 'delete').callsFake(async (opts) => { | ||
if ((opts.url as string).indexOf(`/users/c527a470-a882-481c-981c-ee6efaba85c7/teamwork/installedApps/YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=`) > -1) { | ||
if ((opts.url as string).indexOf(`/users/${userId}/teamwork/installedApps/${appId}`) > -1) { | ||
throw error; | ||
} | ||
throw 'Invalid request'; | ||
}); | ||
|
||
await assert.rejects(command.action(logger, { | ||
options: { | ||
userId: 'c527a470-a882-481c-981c-ee6efaba85c7', | ||
id: 'YzUyN2E0NzAtYTg4Mi00ODFjLTk4MWMtZWU2ZWZhYmE4NWM3IyM0ZDFlYTA0Ny1mMTk2LTQ1MGQtYjJlOS0wZDI4NTViYTA1YTY=', | ||
userId: userId, | ||
id: appId, | ||
force: true | ||
} | ||
} as any), new CommandError(error.error.message)); | ||
|
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