Skip to content

Commit

Permalink
Misc improvements
Browse files Browse the repository at this point in the history
- improve integration test coverage
- rely on genkit's user_engagement function
- clean up deps
  • Loading branch information
andrewbrook committed Nov 13, 2024
1 parent d9f3173 commit 8ab2a5b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 262 deletions.
1 change: 1 addition & 0 deletions ai-user-engagement/functions/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GENKIT_ENV=prod
1 change: 1 addition & 0 deletions ai-user-engagement/functions/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GENKIT_ENV=dev
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import axios from "axios";
import { expect } from "chai";
import { readFileSync } from 'fs';

describe("firebase-ai-user-engagement", () => {
const uri = "http://localhost:5001/demo-test/us-central1/ext-ai-user-engagement-collectEngagement/";

function delay(ms: number) {
return new Promise( resolve => setTimeout(resolve, ms) );
}

it("should collect user feedback", async () => {
const request = {
name: "featureName",
Expand All @@ -16,9 +21,30 @@ describe("firebase-ai-user-engagement", () => {
};

const res = await axios.post(uri, request);
expect(res.data).to.eql({});

return expect(res.data).to.eql({});
}).timeout(10000);
await delay(5000);

// Wait for emulator logs to contain the user feedback message. We do this
// by explicitly setting the Genkit env to "dev" (by using .env.local
// config), which forces logs to be written to console, and by redirecting
// emulator output to a tmp file (see package.json).
let tries = 5;
let foundLog = false;
while (tries > 0) {
const testLogs = readFileSync('/tmp/engagement_test_output', 'utf8');
if (testLogs.indexOf("UserFeedback[featureName]") > 0) {
foundLog = true;
break;
} else {
console.log('.');
}
await delay(10000); // wait 10s
tries--;
}

return expect(foundLog).to.be.true;
}).timeout(60000);

it("should collect user acceptance", async () => {
const request = {
Expand Down
Loading

0 comments on commit 8ab2a5b

Please sign in to comment.