Created
August 12, 2020 16:38
-
-
Save scarney81/512b3ca624d08463a0f642fd168f06a6 to your computer and use it in GitHub Desktop.
courier interview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "[email protected]"}' | |
}, | |
json: true | |
} | |
const result = await send(payload); | |
expect(result).toHaveProperty("statusCode", 204); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const get = async (id: string) => { | |
return { | |
id | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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