diff --git a/.github/workflows/create-story.yml b/.github/workflows/create-story.yml new file mode 100644 index 0000000..419eb53 --- /dev/null +++ b/.github/workflows/create-story.yml @@ -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 diff --git a/create-story-test.mjs b/create-story-test.mjs new file mode 100644 index 0000000..4463536 --- /dev/null +++ b/create-story-test.mjs @@ -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); + });