-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
234 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { convexTest } from "convex-test"; | ||
import { describe, expect, it } from "vitest"; | ||
import { api } from "./_generated/api"; | ||
import schema from "./schema"; | ||
import { modules } from "./test.setup"; | ||
|
||
describe("faqs", () => { | ||
it("creates a FAQ", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
// Create a topic first | ||
const topicId = await t.mutation(api.topics.createTopic, { | ||
topic: "Costs", | ||
}); | ||
|
||
// Create a FAQ | ||
const faqId = await t.mutation(api.faqs.createFAQ, { | ||
question: "How much does the process cost?", | ||
answer: "It varies.", | ||
topics: [topicId], | ||
}); | ||
|
||
// Verify FAQ creation | ||
const faqs = await t.query(api.faqs.getAllFAQs); | ||
const createdFAQ = faqs.find((f) => f._id === faqId); | ||
expect(createdFAQ).toBeTruthy(); | ||
expect(createdFAQ?.question).toBe("How much does the process cost?"); | ||
expect(createdFAQ?.answer).toBe("It varies."); | ||
expect(createdFAQ?.topics).toContain(topicId); | ||
}); | ||
|
||
it("updates a FAQ", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
// Create a topic first | ||
const topicId = await t.mutation(api.topics.createTopic, { | ||
topic: "Costs", | ||
}); | ||
|
||
// Create a FAQ | ||
const faqId = await t.mutation(api.faqs.createFAQ, { | ||
question: "How much does the process cost?", | ||
answer: "It varies.", | ||
topics: [topicId], | ||
}); | ||
|
||
// Update the FAQ | ||
await t.mutation(api.faqs.updateFAQ, { | ||
faqId, | ||
faq: { | ||
question: "How much does the process cost, exactly?", | ||
answer: "It varies a lot.", | ||
topics: [topicId], | ||
}, | ||
}); | ||
|
||
// Verify FAQ update | ||
const faqs = await t.query(api.faqs.getAllFAQs); | ||
const updatedFAQ = faqs.find((f) => f._id === faqId); | ||
expect(updatedFAQ).toBeTruthy(); | ||
expect(updatedFAQ?.question).toBe( | ||
"How much does the process cost, exactly?", | ||
); | ||
expect(updatedFAQ?.answer).toBe("It varies a lot."); | ||
}); | ||
|
||
it("gets all FAQs", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
// Create a topic first | ||
const topicId = await t.mutation(api.topics.createTopic, { | ||
topic: "Costs", | ||
}); | ||
|
||
// Mock FAQs | ||
await t.run(async (ctx) => { | ||
await ctx.db.insert("faqs", { | ||
question: "How much does the process cost?", | ||
answer: "It varies.", | ||
topics: [topicId], | ||
}); | ||
await ctx.db.insert("faqs", { | ||
question: "What documents do I need?", | ||
answer: "You'll need passport, visa, and other supporting documents.", | ||
topics: [topicId], | ||
}); | ||
}); | ||
|
||
// Get all FAQs | ||
const faqs = await t.query(api.faqs.getAllFAQs); | ||
|
||
// Verify FAQs | ||
expect(faqs.length).toBe(2); | ||
expect(faqs[0].question).toBe("How much does the process cost?"); | ||
expect(faqs[1].question).toBe("What documents do I need?"); | ||
}); | ||
|
||
it("deletes a FAQ", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
// Create a topic first | ||
const topicId = await t.mutation(api.topics.createTopic, { | ||
topic: "Costs", | ||
}); | ||
|
||
// Create a FAQ | ||
const faqId = await t.mutation(api.faqs.createFAQ, { | ||
question: "How much does the process cost?", | ||
answer: "It varies.", | ||
topics: [topicId], | ||
}); | ||
|
||
// Verify FAQ creation | ||
const faqs = await t.query(api.faqs.getAllFAQs); | ||
const createdFAQ = faqs.find((f) => f._id === faqId); | ||
expect(createdFAQ).toBeTruthy(); | ||
expect(createdFAQ?.question).toBe("How much does the process cost?"); | ||
expect(createdFAQ?.answer).toBe("It varies."); | ||
expect(createdFAQ?.topics).toContain(topicId); | ||
|
||
// Delete the FAQ | ||
await t.mutation(api.faqs.deleteFAQ, { | ||
faqId, | ||
}); | ||
|
||
// Verify FAQ deletion | ||
const faqsAfter = await t.query(api.faqs.getAllFAQs); | ||
const deletedFAQ = faqsAfter.find((f) => f._id === faqId); | ||
expect(deletedFAQ).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
import { convexTest } from "convex-test"; | ||
import { expect, test } from "vitest"; | ||
import { describe, expect, it } from "vitest"; | ||
import { api } from "./_generated/api"; | ||
import schema from "./schema"; | ||
|
||
// TODO: Remove this import and this file; | ||
// shouldn't need to use it since everything is in the default location | ||
import { modules } from "./test.setup"; | ||
|
||
test("get all quests", async () => { | ||
const t = convexTest(schema, modules); | ||
const quests = await t.query(api.quests.getAllQuests); | ||
expect(quests).toMatchObject([]); | ||
describe("quests", () => { | ||
it("gets all quests", async () => { | ||
const t = convexTest(schema, modules); | ||
const quests = await t.query(api.quests.getAllQuests); | ||
expect(quests).toMatchObject([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { convexTest } from "convex-test"; | ||
import { describe, expect, it } from "vitest"; | ||
import { api } from "./_generated/api"; | ||
import schema from "./schema"; | ||
import { modules } from "./test.setup"; | ||
|
||
describe("topics", () => { | ||
it("creates a topic", async () => { | ||
const t = convexTest(schema, modules); | ||
// Create a topic | ||
const topicId = await t.mutation(api.topics.createTopic, { | ||
topic: "Immigration", | ||
}); | ||
|
||
// Verify topic creation | ||
const topics = await t.query(api.topics.getAllTopics); | ||
const createdTopic = topics.find((t) => t._id === topicId); | ||
expect(createdTopic).toBeTruthy(); | ||
expect(createdTopic?.topic).toBe("Immigration"); | ||
}); | ||
|
||
it("updates a topic", async () => { | ||
const t = convexTest(schema, modules); | ||
// Create a topic | ||
const topicId = await t.mutation(api.topics.createTopic, { | ||
topic: "Immigration", | ||
}); | ||
|
||
// Update the topic | ||
await t.mutation(api.topics.updateTopic, { | ||
topicId, | ||
topic: "Adoption", | ||
}); | ||
|
||
// Verify topic update | ||
const topics = await t.query(api.topics.getAllTopics); | ||
const updatedTopic = topics.find((t) => t._id === topicId); | ||
expect(updatedTopic).toBeTruthy(); | ||
expect(updatedTopic?.topic).toBe("Adoption"); | ||
}); | ||
|
||
it("deletes a topic", async () => { | ||
const t = convexTest(schema, modules); | ||
// Create a topic | ||
const topicId = await t.mutation(api.topics.createTopic, { | ||
topic: "Immigration", | ||
}); | ||
|
||
// Verify topic creation | ||
const topics = await t.query(api.topics.getAllTopics); | ||
const createdTopic = topics.find((t) => t._id === topicId); | ||
expect(createdTopic).toBeTruthy(); | ||
expect(createdTopic?.topic).toBe("Immigration"); | ||
|
||
// Delete the topic | ||
await t.mutation(api.topics.deleteTopic, { | ||
topicId, | ||
}); | ||
|
||
// Verify topic deletion | ||
const topicsAfter = await t.query(api.topics.getAllTopics); | ||
const deletedTopic = topicsAfter.find((t) => t._id === topicId); | ||
expect(deletedTopic).toBeUndefined(); | ||
}); | ||
|
||
it("gets all topics", async () => { | ||
const t = convexTest(schema, modules); | ||
|
||
// Mock topics | ||
await t.run(async (ctx) => { | ||
await ctx.db.insert("topics", { topic: "Immigration" }); | ||
await ctx.db.insert("topics", { topic: "Adoption" }); | ||
await ctx.db.insert("topics", { topic: "Costs" }); | ||
}); | ||
|
||
// Get all topics | ||
const topics = await t.query(api.topics.getAllTopics); | ||
|
||
// Verify topics | ||
expect(topics.length).toBe(3); | ||
expect(topics[0].topic).toBe("Immigration"); | ||
expect(topics[1].topic).toBe("Adoption"); | ||
expect(topics[2].topic).toBe("Costs"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters