adding a type for the options object

This commit is contained in:
Bryan Kendall
2018-11-26 15:21:17 -08:00
parent ef69d5c3fc
commit 4158078618
2 changed files with 8 additions and 4 deletions

View File

@@ -4,12 +4,16 @@ import { fetch } from "../fetchWebSetup";
const INIT_TEMPLATE = readFileSync(`${__dirname}/../../templates/hosting/init.js`, "utf8");
export interface ImplicitInitRequest {
projectNumber: number;
}
export interface ImplicitInitResponse {
js: string;
json: string;
}
export async function init(options: any): Promise<ImplicitInitResponse> {
export async function init(options: ImplicitInitRequest): Promise<ImplicitInitResponse> {
const config = await fetch(options);
const configJson = JSON.stringify(config, null, 2);
return {

View File

@@ -15,15 +15,15 @@ describe("implicitInit", () => {
afterEach(() => sandbox.restore());
it("should fetch the information about the project", async () => {
await init({});
await init({ projectNumber: 1 });
sinon.assert.calledOnce(fetchWebSetup.fetch as sinon.SinonStub);
sinon.assert.calledWithExactly(fetchWebSetup.fetch as sinon.SinonStub, {});
sinon.assert.calledWithExactly(fetchWebSetup.fetch as sinon.SinonStub, { projectNumber: 1 });
});
it("should insert the config into the js value returned", async () => {
(fetchWebSetup.fetch as sinon.SinonStub).resolves({ foo: "bar" });
const data = await init({});
const data = await init({ projectNumber: 1 });
expect(data.js).to.contain(`"foo": "bar"`);
});