Skip to content

Commit

Permalink
fixup! More command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrahms committed Feb 22, 2024
1 parent 5841f22 commit e755965
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/commands/__tests__/ls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("ls", () => {
});

it("should print list response", async () => {
await lsCommand(yargs).parse(command);
await lsCommand(yargs()).parse(command);
expect(mockPrint1.mock.calls).toMatchSnapshot();
expect(mockPrint2.mock.calls).toMatchSnapshot();
});
Expand All @@ -52,7 +52,7 @@ Unknown argument: foo`,
});

it("should print error message", async () => {
const error = await failure(lsCommand(yargs), command);
const error = await failure(lsCommand(yargs()), command);
expect(error).toMatchSnapshot();
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/commands/__tests__/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("request", () => {
(isPreexisting, isPersistent, should) => {
it(`should${should ? "" : " not"} print request response`, async () => {
mockFetch({ isPreexisting, isPersistent });
await requestCommand(yargs).parse(command);
await requestCommand(yargs()).parse(command);
expect(mockPrint2.mock.calls).toMatchSnapshot();
expect(mockPrint1).not.toHaveBeenCalled();
});
Expand All @@ -50,7 +50,7 @@ describe("request", () => {

it("should wait for access", async () => {
mockFetch();
const promise = requestCommand(yargs).parse(`${command} --wait`);
const promise = requestCommand(yargs()).parse(`${command} --wait`);
const wait = sleep(10);
await expect(wait).resolves.toBeUndefined();
(onSnapshot as any).trigger({
Expand Down Expand Up @@ -84,7 +84,7 @@ Unknown argument: foo`,
});

it("should print error message", async () => {
const error = await failure(requestCommand(yargs), command);
const error = await failure(requestCommand(yargs()), command);
expect(error).toMatchSnapshot();
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/commands/aws/__tests__/__snapshots__/role.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`aws role a single installed account with Okta SAML assume should assume a role 1`] = `
exports[`aws role a single installed account with Okta SAML assume should assume a role: stderr 1`] = `
[
[
"Execute the following commands:
Expand All @@ -10,13 +10,13 @@ exports[`aws role a single installed account with Okta SAML assume should assume
"
Or, populate these environment variables using BASH command substitution:
$(p0 aws role assume undefined)
$(p0 aws role assume Role1)
",
],
]
`;

exports[`aws role a single installed account with Okta SAML assume should assume a role 2`] = `
exports[`aws role a single installed account with Okta SAML assume should assume a role: stdout 1`] = `
[
[
" export AWS_ACCESS_KEY_ID=test-access-key
Expand All @@ -26,15 +26,15 @@ exports[`aws role a single installed account with Okta SAML assume should assume
]
`;

exports[`aws role a single installed account with Okta SAML ls lists roles 1`] = `
exports[`aws role a single installed account with Okta SAML ls lists roles: stderr 1`] = `
[
[
"Your available roles for account 1:",
],
]
`;

exports[`aws role a single installed account with Okta SAML ls lists roles 2`] = `
exports[`aws role a single installed account with Okta SAML ls lists roles: stdout 1`] = `
[
[
" Role1
Expand Down
15 changes: 7 additions & 8 deletions src/commands/aws/__tests__/role.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("aws role", () => {
["assume", "aws role assume Role1"],
])("%s", (_, command) => {
it("should print a friendly error message", async () => {
const error = await failure(awsCommand(yargs), command);
const error = await failure(awsCommand(yargs()), command);
expect(error).toMatchInlineSnapshot(
`"Account 1 (test) is not configured for Okta SAML login."`
);
Expand All @@ -68,17 +68,16 @@ describe("aws role", () => {
});
describe("assume", () => {
it("should assume a role", async () => {
await awsCommand(yargs).parse("aws role assume Role1");
expect(mockPrint2.mock.calls).toMatchSnapshot();
expect(mockPrint1.mock.calls).toMatchSnapshot();
await awsCommand(yargs()).parse("aws role assume Role1");
expect(mockPrint2.mock.calls).toMatchSnapshot("stderr");
expect(mockPrint1.mock.calls).toMatchSnapshot("stdout");
});
});
describe("ls", () => {
const command = "aws role ls";
it("lists roles", async () => {
await awsCommand(yargs).parse(command);
expect(mockPrint2.mock.calls).toMatchSnapshot();
expect(mockPrint1.mock.calls).toMatchSnapshot();
await awsCommand(yargs()).parse("aws role ls");
expect(mockPrint2.mock.calls).toMatchSnapshot("stderr");
expect(mockPrint1.mock.calls).toMatchSnapshot("stdout");
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import yargs from "yargs";
/** Logs in the user
*
* Currently only supports login to a single organization. Login credentials, together
* with organization details, are saved to ~/.p0/identity.json.
* with organization details, are saved to {@link IDENTITY_FILE_PATH}.
*/
export const login = async (
args: { org: string },
Expand Down

0 comments on commit e755965

Please sign in to comment.