Skip to content

Instantly share code, notes, and snippets.

@hakant
Last active March 25, 2017 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakant/a2d1c53fdaa5e7c0d99eeb8e8b4022e2 to your computer and use it in GitHub Desktop.
Save hakant/a2d1c53fdaa5e7c0d99eeb8e8b4022e2 to your computer and use it in GitHub Desktop.
"use strict";
import * as nconf from 'nconf';
nconf.argv().env().file({ file: 'config.json' });
import databaseSetup from "../../infrastructure/DatabaseSetup";
import application from "../../application/application";
import { GetIdeasRequest, GetIdeasResponse } from "../../scenarios/GetIdeas";
import { InsertIdeaRequest, InsertIdeaResponse } from "../../scenarios/InsertIdea";
import testHelpers from "./TestHelpers";
let tableName;
describe("Insert and Get Ideas Scenarios", function () {
beforeEach(async (done) => {
tableName = `Ideas_${testHelpers.GenerateRandomNumber()}`;
await databaseSetup.SetupNoSqlTables(tableName);
done();
});
afterEach(async (done) => {
await databaseSetup.BringDownNoSqlTables(tableName);
done();
});
it("Initially there are no ideas", async function (done) {
// Act
var request = new GetIdeasRequest();
request.user = {
id: "1",
username: "hakant",
displayName: "Hakan Tuncer",
_json: {
avatar_url: "AvatarURL"
}
};
var response = await application.ExecuteAsync<GetIdeasRequest, GetIdeasResponse>(request);
expect(response.ideas.length).toBe(0);
done();
});
it("When there is an idea in the system, it's fetched and returned correctly", async function (done) {
// Setup
let testLoggedOnUser: ILoggedOnUser = {
id: "1",
username: "hakant",
displayName: "Hakan Tuncer",
_json: {
avatar_url: "AvatarURL"
}
};
let idea = testHelpers.GenerateIdeaWithId("123", testLoggedOnUser);
await testHelpers.InsertIdea(testLoggedOnUser, idea);
// Act
var request = new GetIdeasRequest();
request.user = testLoggedOnUser;
var response = await application.ExecuteAsync<GetIdeasRequest, GetIdeasResponse>(request);
expect(response.ideas.length).toBe(1);
expect(response.ideas[0]).toEqual(idea);
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment