diff --git a/README.md b/README.md index a03b8451..3e066639 100644 --- a/README.md +++ b/README.md @@ -107,9 +107,9 @@ const profilesApi = new ProfilesApi(session) let profile: ProfileCreateQuery = { data: { - type: ProfileEnum.Profile, - attributes: { - email: "typescript_test_1@klaviyo-demo.com" + type: ProfileEnum.Profile, + attributes: { + email: "typescript_test_1@klaviyo-demo.com", } } } @@ -148,7 +148,7 @@ There is also an optional `Klaviyo` import that has all the Apis and Auth, if yo import { Klaviyo } from 'klaviyo-api' const profilesApi = new Klaviyo.ProfilesApi(new Klaviyo.Auth.ApiKeySession("< YOUR API KEY HERE >", retry)) -```` +``` ### Inspecting Errors @@ -171,11 +171,11 @@ profilesApi.createProfile(profile).then(result => { ### Uploading an image by file -The `ImageApi` exposes `uploadImageFromFile()` +The `ImagesApi` exposes `uploadImageFromFile()` ```Typescript import fs from 'fs' -import {ApiKeySession, ImageApi } from 'klaviyo-api' +import {ApiKeySession, ImagesApi } from 'klaviyo-api' const session = new ApiKeySession("< YOUR API KEY HERE >") const imageApi = new ImagesApi(session) @@ -183,7 +183,7 @@ imageApi.uploadImageFromFile(fs.createReadStream("./test_image.jpeg")).then(resu console.log(result.body) }).catch(error => { console.log(error) -} +}); ``` ### Global Api Key diff --git a/test/readme.test.ts b/test/readme.test.ts new file mode 100644 index 00000000..b90043c6 --- /dev/null +++ b/test/readme.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, test } from "@jest/globals"; +import fs from "fs"; +import path from "path"; + +const readme = fs.readFileSync(path.join(__dirname, "..", "README.md"), "utf8"); + +describe("README examples", () => { + test("createProfile example includes the fixed email comma", () => { + expect(readme).toContain('email: "typescript_test_1@klaviyo-demo.com",'); + expect(readme).not.toContain('email: "typescript_test_1@klaviyo-demo.com"\n }'); + }); + + test("organizational helpers code fence closes with triple backticks", () => { + expect(readme).toContain( + 'const profilesApi = new Klaviyo.ProfilesApi(new Klaviyo.Auth.ApiKeySession("< YOUR API KEY HERE >", retry))\n```' + ); + expect(readme).not.toContain( + 'const profilesApi = new Klaviyo.ProfilesApi(new Klaviyo.Auth.ApiKeySession("< YOUR API KEY HERE >", retry))\n````' + ); + }); + + test("image upload example consistently uses ImagesApi and closes the catch chain", () => { + expect(readme).toContain('The `ImagesApi` exposes `uploadImageFromFile()`'); + expect(readme).toContain("import {ApiKeySession, ImagesApi } from 'klaviyo-api'"); + expect(readme).toContain('const imageApi = new ImagesApi(session)'); + expect(readme).not.toContain("import {ApiKeySession, ImageApi } from 'klaviyo-api'"); + expect(readme).not.toContain('The `ImageApi` exposes `uploadImageFromFile()`'); + expect(readme).toContain( + 'const imageApi = new ImagesApi(session)\nimageApi.uploadImageFromFile(fs.createReadStream("./test_image.jpeg")).then(result => {\n console.log(result.body)\n}).catch(error => {\n console.log(error)\n});' + ); + }); +});