Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Fix build on circle CI #21

Merged
merged 10 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/commands/messages/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { Command, flags } from "@oclif/command";
import cli from "cli-ux";
import * as parse from "csv-parse";
import * as fs from "fs";
import * as t from "io-ts";
import * as transform from "stream-transform";

import {
config,
getCosmosEndpoint,
getCosmosReadonlyKey,
getCosmosWriteKey
} from "../../utils/azure";
import { parseMessagePath } from "../../utils/parser";
Expand Down Expand Up @@ -42,6 +40,7 @@ export default class MessagesAttributes extends Command {
this.exit();
}

// tslint:disable-next-line: no-inferred-empty-object-type
const messageDelta = [
{
key: "isPending",
Expand Down Expand Up @@ -95,7 +94,7 @@ export default class MessagesAttributes extends Command {
cli.action.stop();

const client = new cosmos.CosmosClient({ endpoint, auth: { key } });
const database = await client.database(config.cosmosDatabaseName);
const database = client.database(config.cosmosDatabaseName);
const container = database.container(config.cosmosMessagesContainer);

const updateMessage = async (fiscalCode: string, messageId: string) => {
Expand Down Expand Up @@ -133,7 +132,7 @@ export default class MessagesAttributes extends Command {
.pipe(transformer)
.pipe(process.stdout);

await new Promise((res, rej) => parser.on("end", res));
await new Promise((res, _) => parser.on("end", res));
} catch (e) {
this.error(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/profiles/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default class ProfilesList extends Command {

cli.action.start("Querying profiles...");
const client = new cosmos.CosmosClient({ endpoint, auth: { key } });
const database = await client.database("agid-documentdb-test");
const database = client.database("agid-documentdb-test");
const container = database.container("profiles");
const response = await container.items.query(
const response = container.items.query(
"SELECT c.fiscalCode, c._ts FROM c WHERE c.version = 0",
{
enableCrossPartitionQuery: true
Expand Down
18 changes: 18 additions & 0 deletions src/utils/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ export const getStorageConnection = async (name: string) =>
(await execa(
`az storage account show-connection-string --name ${name} --output tsv`
)).stdout;

/**
* hasCosmosConnection checks if the host has az cli installed and resouceGroup and name
* are valid inputs for cosmosdb
*/
export const hasCosmosConnection = (resourceGroup: string, name: string) => {
try {
execa.sync(
Undermaken marked this conversation as resolved.
Show resolved Hide resolved
`az cosmosdb show -g ${resourceGroup} -n ${name} --query documentEndpoint -o tsv`
);
Undermaken marked this conversation as resolved.
Show resolved Hide resolved
execa.sync(
`az cosmosdb list-keys -g ${resourceGroup} -n ${name} --query primaryReadonlyMasterKey -o tsv`
);
return true;
} catch (e) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be useful to log the exception to the console, at least it gives you a hint on why the command failed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used cli.log instead of cli.error because this one causes the test failure

}
};
22 changes: 11 additions & 11 deletions test/commands/hello.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {expect, test} from '@oclif/test'
import { expect, test } from "@oclif/test";

describe('hello', () => {
describe("hello", () => {
test
.stdout()
.command(['hello'])
.it('runs hello', ctx => {
expect(ctx.stdout).to.contain('hello world')
})
.command(["hello"])
.it("runs hello world", ctx => {
expect(ctx.stdout).to.contain("hello world");
});

test
.stdout()
.command(['hello', '--name', 'jeff'])
.it('runs hello --name jeff', ctx => {
expect(ctx.stdout).to.contain('hello jeff')
})
})
.command(["hello", "--name", "jeff"])
.it("runs hello --name jeff", ctx => {
expect(ctx.stdout).to.contain("hello jeff");
});
});
44 changes: 28 additions & 16 deletions test/commands/users/list.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import {expect, test} from '@oclif/test'
import { expect, test } from "@oclif/test";
import { hasCosmosConnection } from "../../../src/utils/azure";

describe('users:list', () => {
test
.stdout()
.command(['users:list'])
.it('runs hello', ctx => {
expect(ctx.stdout).to.contain('hello world')
})

test
.stdout()
.command(['users:list', '--name', 'jeff'])
.it('runs hello --name jeff', ctx => {
expect(ctx.stdout).to.contain('hello jeff')
})
})
describe("list all profiles", () => {
const isCosmosConnectionAvailable = hasCosmosConnection(
"agid-rg-test",
"agid-cosmosdb-test"
);
/**
* if host has the az client installed and valid cosmos credentials we test command first output line matches
* the header row (fiscalCode column name). Otherwise the test expects for an error with 2 as exit status
*/
if (isCosmosConnectionAvailable) {
Undermaken marked this conversation as resolved.
Show resolved Hide resolved
test
.stdout()
.command(["profiles:list"])
.it("runs profiles command to list all users", ctx => {
expect(ctx.stdout).match(/^fiscalCode/);
});
} else {
test
.stdout()
.command(["profiles:list"])
.exit(2)
.it(
"check the command goes in error (no cosmos credential available or az client not installed)"
);
}
});
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
--watch-extensions ts
--recursive
--reporter spec
--timeout 5000
--timeout 15000