diff --git a/package.json b/package.json index 77333e7..8497abd 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "danger-plugin", "learning mentor trivia" ], - "version": "0.0.0-development", + "version": "0.1.0", "main": "dist/index.js", "types": "types/index.d.ts", "scripts": { diff --git a/src/index.ts b/src/index.ts index ec01f28..93baf6f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,5 +11,5 @@ export declare function markdown(message: string): void * Level up your programming skills by getting bite-sized tips and tricks in your pull requests. */ export default function mentor() { - message(RandomTip().text) + message(RandomTip().toMarkdown()) } diff --git a/src/tip.test.ts b/src/tip.test.ts new file mode 100644 index 0000000..ed1728f --- /dev/null +++ b/src/tip.test.ts @@ -0,0 +1,15 @@ +import Tip from "./tip" + +describe("Tip", () => { + describe("#toMarkdown", () => { + it("concats the text and the source", () => { + expect(new Tip("A tip with a source.", new URL("http://example.com")).toMarkdown()).toEqual( + "A tip with a source. Source: [http://example.com/](http://example.com/)" + ) + }) + + it("leaves out the source if not present", () => { + expect(new Tip("A tip with a source.").toMarkdown()).toEqual("A tip with a source.") + }) + }) +}) diff --git a/src/tip.ts b/src/tip.ts index 39fd155..0d3561b 100644 --- a/src/tip.ts +++ b/src/tip.ts @@ -1,7 +1,17 @@ export default class Tip { - text: string + private text: string + private source?: URL - constructor(text: string) { + constructor(text: string, source?: URL) { this.text = text + this.source = source + } + + toMarkdown(): string { + if (this.source) { + return `${this.text} Source: [${this.source}](${this.source})` + } + + return this.text } }