Skip to content

Commit

Permalink
Merge pull request #9 from Ho-Wan/develop
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
ho-wan authored Jan 19, 2019
2 parents ddb05a2 + 8f8d639 commit 9ab8abe
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 40 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 0.1.1 (19 Jan 2019)
- Minor documentation update. Improved api tests.

## 0.1.0 (19 Jan 2019)
- Reinitialized repo using yeoman generator

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Welcome to Trello Viewer for VS Code! This extension provides the following feat
- View selected card using the markdown previewer and open to the side.
- See formatted checklists and cover image for the card.
- Assign a favourite list to easily access cards.
- Saves credentials to use between sessions.>>>
- Saves credentials to use between sessions.
- Shows only starred boards as default.

## Authenication
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-trello-viewer",
"displayName": "Trello Viewer",
"description": "View Trello cards in VS Code, browse user's boards and lists.",
"version": "0.1.0",
"version": "0.1.1",
"publisher": "Ho-Wan",
"author": {
"name": "Ho-Wan To",
Expand Down
195 changes: 158 additions & 37 deletions src/test/TrelloUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import * as assert from "assert";
import { TrelloUtils } from "../trello/TrelloUtils";
import * as sinon from "sinon";
import axios, { AxiosPromise } from "axios";

import { TrelloUtils } from "../trello/TrelloUtils";
import { TrelloCard, TrelloList, TrelloBoard } from "../trello/trelloComponents";

suite("TrelloUtils", () => {
// Avoid console error from globalState.get()
// Use sandbox to avoid console error from globalState.get()
const consoleErrorSandbox = sinon.createSandbox();
consoleErrorSandbox.stub(console, "error");
let trello: TrelloUtils = new TrelloUtils();
consoleErrorSandbox.restore();

suite("VS Code", () => {
const API_KEY = "SomeApiKey123";
const API_TOKEN = "SomeApiToken12345";
const API_KEY = "SomeApiKey";
const API_TOKEN = "SomeApiToken";
test("SetTrelloCredential correctly resolves key and token", async () => {
const setTrelloCredentialStub = sinon.stub(trello, "setTrelloCredential");
setTrelloCredentialStub.onCall(0).returns(Promise.resolve(API_KEY));
Expand All @@ -28,45 +31,163 @@ suite("TrelloUtils", () => {
});

suite("Trello API", () => {
const BOARD_ID = "5c2b3cdaa0696d3fd39d776e";
const LIST_ID = "5c2b3d25a9970548e6e38318";
const CARD_ID = "5c2b3d3ae3d7314d2876f4fd";

test("getBoardById returns board data", async () => {
const trelloBoard = await trello.getBoardById(BOARD_ID, false);
assert.equal(trelloBoard.id, BOARD_ID);
assert.equal(typeof trelloBoard.name, "string");
});
const trelloApiRequestStub = sinon.stub(trello, "trelloApiRequest");

test("getListById returns list data", async () => {
const trelloList = await trello.getListById(LIST_ID, false);
assert.equal(trelloList.id, LIST_ID);
assert.equal(typeof trelloList.name, "string");
assert.equal(trelloList.idBoard, BOARD_ID);
});
suite("Trello API", () => {
const BOARD_ID = "123";
const LIST_ID = "456";
const CARD_ID = "789";

test("getCardById returns card data", async () => {
const trelloCard = await trello.getCardById(CARD_ID, false);
assert.equal(trelloCard.id, CARD_ID);
assert.equal(typeof trelloCard.name, "string");
assert.equal(typeof trelloCard.url, "string");
assert.equal(typeof trelloCard.desc, "string");
assert.equal(trelloCard.idChecklists.length >= 0, true);
});
setup(() => {
trelloApiRequestStub.reset();
});

test("getListsFromBoard returns list as array", async () => {
const trelloLists = await trello.getListsFromBoard(BOARD_ID, false);
assert.equal(trelloLists[0].id, LIST_ID);
});
suiteTeardown(() => {
trelloApiRequestStub.restore();
});

test("getBoardById returns mock board data", async () => {
const data = new Promise(r =>
r({
id: BOARD_ID,
name: "test_board",
})
);
trelloApiRequestStub.returns(data);
const trelloBoard: TrelloBoard = await trello.getBoardById(BOARD_ID, false);

assert.equal(trelloBoard.id, BOARD_ID);
assert.equal(trelloBoard.name, "test_board");
});

test("getListById returns mock list data", async () => {
const data = new Promise(r =>
r({
id: LIST_ID,
name: "test_list",
idBoard: BOARD_ID,
})
);
trelloApiRequestStub.returns(data);
const trelloList: TrelloList = await trello.getListById(LIST_ID, false);

test("getCardsFromList returns card as array", async () => {
const trelloCards = await trello.getCardsFromList(LIST_ID, false);
assert.equal(trelloCards[0].id, CARD_ID);
assert.equal(trelloList.id, LIST_ID);
assert.equal(trelloList.name, "test_list");
assert.equal(trelloList.idBoard, BOARD_ID);
});

test("getCardById returns mock card data", async () => {
const data = new Promise(r =>
r({
id: CARD_ID,
name: "test_card",
attachments: [
{
url: "test_attachment_url",
},
],
url: "test_url",
desc: "test_desc",
idChecklists: ["checklist_id_1", "checklist_id_2"],
})
);
trelloApiRequestStub.returns(data);
const trelloCard: TrelloCard = await trello.getCardById(CARD_ID, false);

assert.equal(trelloCard.id, CARD_ID);
assert.equal(trelloCard.attachments[0].url, "test_attachment_url");
assert.equal(trelloCard.name, "test_card");
assert.equal(trelloCard.url, "test_url");
assert.equal(trelloCard.desc, "test_desc");
assert.equal(trelloCard.idChecklists[0], "checklist_id_1");
assert.equal(trelloCard.idChecklists[1], "checklist_id_2");
});

test("getListsFromBoard returns list as array", async () => {
const data = new Promise(r =>
r([
{
id: "list_id_1",
name: "test_list_1",
idBoard: BOARD_ID,
},
{
id: "list_id_2",
name: "test_list_2",
idBoard: BOARD_ID,
},
])
);
trelloApiRequestStub.returns(data);
const trelloLists: TrelloList[] = await trello.getListsFromBoard(BOARD_ID, false);
assert.equal(trelloLists[0].id, "list_id_1");
assert.equal(trelloLists[1].id, "list_id_2");
});

test("getCardsFromList returns card as array", async () => {
const data = new Promise(r =>
r([
{
id: "card_id_1",
name: "test_card_1",
desc: "test_desc_1",
},
{
id: "card_id_2",
name: "test_card_2",
desc: "test_desc_2",
},
])
);
trelloApiRequestStub.returns(data);
const trelloCards = await trello.getCardsFromList(LIST_ID, false);
assert.equal(trelloCards[0].id, "card_id_1");
assert.equal(trelloCards[1].id, "card_id_2");
});
});

test("getBoards returns null if credentials not provided", async () => {
const trelloBoards = await trello.getBoards(false);
assert.equal(trelloBoards, null);
suite("trelloApiRequest", () => {
const credentialsStub = sinon.stub(trello, "isCredentialsProvided");

suiteSetup(() => {
trelloApiRequestStub.restore();
});

setup(() => {
credentialsStub.reset();
});

suiteTeardown(() => {
credentialsStub.restore();
});

test("trelloApiRequest returns null if no credentials", async () => {
credentialsStub.returns(false);
const response = await trello.trelloApiRequest("test_id", {});
assert.equal(response, null);
});

test("trelloApiRequest returns response with correct data", async () => {
credentialsStub.returns(true);
const mockResponse: AxiosPromise = new Promise(r =>
r({
data: {
id: "123",
desc: "test_description",
},
status: 200,
statusText: "Ok",
headers: "test_headers",
config: {},
})
);
sinon.stub(axios, "get").returns(mockResponse);
const response = await trello.trelloApiRequest("test_id", {});
assert.deepEqual(response, {
id: "123",
desc: "test_description",
});
});
});
});
});
2 changes: 1 addition & 1 deletion src/trello/TrelloUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class TrelloUtils {
vscode.window.showInformationMessage(info);
}

private async trelloApiRequest(url: string, params: object, credentialsRequired: boolean = true): Promise<any> {
async trelloApiRequest(url: string, params: object, credentialsRequired: boolean = true): Promise<any> {
if (credentialsRequired && !this.isCredentialsProvided()) {
vscode.window.showWarningMessage("Credentials Missing: please provide API key and token to use.");
return null;
Expand Down

0 comments on commit 9ab8abe

Please sign in to comment.