Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
}
Expand Down Expand Up @@ -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

Expand All @@ -171,19 +171,19 @@ 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)
imageApi.uploadImageFromFile(fs.createReadStream("./test_image.jpeg")).then(result => {
console.log(result.body)
}).catch(error => {
console.log(error)
}
});
```

### Global Api Key
Expand Down
32 changes: 32 additions & 0 deletions test/readme.test.ts
Original file line number Diff line number Diff line change
@@ -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});'
);
});
});