Skip to content

Instantly share code, notes, and snippets.

@scarney81
Created August 12, 2020 16:38
Show Gist options
  • Save scarney81/512b3ca624d08463a0f642fd168f06a6 to your computer and use it in GitHub Desktop.
Save scarney81/512b3ca624d08463a0f642fd168f06a6 to your computer and use it in GitHub Desktop.
courier interview
{
"name": "vanilla-typescript",
"version": "1.0.0",
"description": "JavaScript and TypeScript example starter project",
"main": "index.html",
"scripts": {
"start": "parcel index.html --open",
"build": "parcel build index.html"
},
"dependencies": {
"jest": "26.3.0"
},
"devDependencies": {
"parcel-bundler": "^1.6.1"
},
"keywords": [
"typescript",
"javascript"
]
}
import { send } from "./send";
it("should send message", async () => {
const payload = {
body: {
event: 'NEW_SIGNUP',
recipient: '8ec8c99a-c5f7-455b-9f60-8222b8a27056',
brand: 'W50NC77P524K14M5300PGPEK4JMJ',
data: '{"name": "Jane Doe","age": 27}',
profile: '{"phone_number": "2025550125","email": "hello@example.com"}'
},
json: true
}
const result = await send(payload);
expect(result).toHaveProperty("statusCode", 204);
});
import { get as getProfile } from "./services/profile";
import { Json } from "./types";
interface IRequest {
headers?: {
[key: string]: string;
};
body?: Json & {
profile: string
};
}
interface IResponse {
body?: Json;
statusCode?: number;
}
type SendFn = (request: IRequest) => Promise<IResponse>;
export const send: SendFn = async (request) => {
const profile = await getProfile(request?.body?.profile);
console.log(profile);
// TODO: more stuff
return {
statusCode: 204
};
};
export const get = async (id: string) => {
return {
id
};
};
export type Json = JsonMap | JsonArray | string | number | boolean | null;
export interface JsonMap {
[member: string]: string | number | boolean | null | JsonArray | JsonMap;
}
export interface JsonArray
extends Array<string | number | boolean | null | JsonArray | JsonMap> {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment