Skip to content
Draft
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
53 changes: 53 additions & 0 deletions .github/workflows/create-story.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Create Story Test

on:
pull_request:
branches:
- main

jobs:
create-story-test:
runs-on: ubuntu-latest
name: Create Story Test
timeout-minutes: 5
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- name: Cache node modules
uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install dependencies
run: npm ci

- name: Build project
run: npm run build

- name: Run create story test
env:
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
run: node create-story-test.mjs

conclude:
runs-on: ubuntu-latest
name: Create Story Test Complete
needs: [create-story-test]
permissions: {}
steps:
- run: echo '### Create story test passed! 🎉' >> $GITHUB_STEP_SUMMARY
45 changes: 45 additions & 0 deletions create-story-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { OpenAI } from "openai";
import { createStory } from "./dist/cjs/index.js";

/**
* Test that verifies the createStory function works end-to-end
*/

const apiKey = process.env.OPENAI_API_KEY || process.env.OPENAI_TOKEN;

if (!apiKey) {
console.error("Error: OPENAI_API_KEY or OPENAI_TOKEN environment variable is required");
process.exit(1);
}

const openai = new OpenAI({ apiKey });

console.log("🚀 Starting create story test\n");

async function testCreateStory() {
console.log("📝 Testing createStory()");
const story = await createStory("A short tale about a brave mouse", openai);

if (!story.prompt || !story.title || !story.content || !story.image) {
throw new Error("Missing required fields in story payload");
}

if (typeof story.temperature !== "number") {
throw new Error("Temperature should be a number");
}

console.log(`✅ createStory passed - Generated story titled: "${story.title}"`);
console.log(` Content length: ${story.content.length} chars`);
console.log(` Temperature: ${story.temperature}`);
console.log(` Image URL: ${story.image.length > 50 ? story.image.substring(0, 50) + "..." : story.image}`);
}

testCreateStory()
.then(() => {
console.log("\n🎉 Create story test passed!");
process.exit(0);
})
.catch(error => {
console.error("\n❌ Create story test failed:", error.message);
process.exit(1);
});
Loading