Skip to content

Commit

Permalink
*: add simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
montyanderson committed Oct 3, 2024
1 parent 177fe41 commit 3a73a35
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 15 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: Validate Formatting & Types
name: Formatting, Types, & Test

on: [push, pull_request]

jobs:
validate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
validate:
runs-on: ubuntu-latest

- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
steps:
- uses: actions/checkout@v3

- run: deno fmt --check
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- run: deno check prodia.ts
- run: deno fmt --check

- run: deno check prodia.ts

- run: deno test --allow-env --allow-net
29 changes: 29 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions test/v2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { assertEquals } from "jsr:@std/assert";
import { createProdia } from "../v2/index.ts";

const token = Deno.env.get("PRODIA_TOKEN");

if(typeof token !== "string") {
throw new Error("PRODIA_TOKEN is not set");
}

const isJpeg = (image: ArrayBuffer): boolean => {
const view = new Uint8Array(image);

return view[0] === 0xFF && view[1] === 0xD8;
};

await Deno.test("Example Job: JPEG Output", async () => {
const client = createProdia({
token
});

const job = await client.job({
"type": "inference.flux.dev.txt2img.v1",
"config": {
"prompt": "puppies in a cloud, 4k",
"steps": 1,
"width": 1024,
"height": 1024
}
});

const image = await job.arrayBuffer();

assertEquals(isJpeg(image), true, "Image should be a JPEG");
});
9 changes: 5 additions & 4 deletions v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ export const createProdia = ({
response = await fetch(`${baseUrl}/job`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
Accept: options.accept,
"Authorization": `Bearer ${token}`,
"Accept": options.accept,
"Content-Type": "application/json"
},
body: JSON.stringify(params),
});
Expand All @@ -95,13 +96,13 @@ export const createProdia = ({

if (response.status === 429) {
throw new ProdiaCapacityError(
"CapacityError: Unable to schedule job with current token",
"ProdiaCapacityError: Unable to schedule job with current token",
);
}

if (response.status < 200 || response.status > 299) {
throw new ProdiaBadResponseError(
"BadResponseError: Invalid response from Prodia API",
`ProdiaBadResponseError: ${response.status} ${response.statusText}`,
);
}

Expand Down

0 comments on commit 3a73a35

Please sign in to comment.