Skip to content

Commit 486a270

Browse files
committed
test: cover collection config guardrails
1 parent a256504 commit 486a270

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/config.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,46 @@ describe("Multi-Collection Configuration", () => {
6868
});
6969
});
7070

71+
it("should prefer new multi-collection parameters when both config styles are present", () => {
72+
process.env.FIRESTORE_COLLECTION_PATH = "books";
73+
process.env.TYPESENSE_COLLECTION_NAME = "books";
74+
process.env.FIRESTORE_COLLECTION_FIELDS = "title,author";
75+
process.env.FLATTEN_NESTED_DOCUMENTS = "true";
76+
process.env.FIRESTORE_COLLECTION_PATHS = "users,products";
77+
process.env.TYPESENSE_COLLECTION_NAMES = "users,products";
78+
process.env.FIRESTORE_COLLECTION_FIELDS_LIST = "name,email|title,description";
79+
process.env.FLATTEN_NESTED_DOCUMENTS_LIST = "false,true";
80+
81+
const collectionMap = config.createCollectionConfigMap();
82+
83+
expect(collectionMap).toEqual({
84+
users: {
85+
firestorePath: "users",
86+
typesenseCollection: "users",
87+
fields: ["name", "email"],
88+
flattenNested: false,
89+
},
90+
products: {
91+
firestorePath: "products",
92+
typesenseCollection: "products",
93+
fields: ["title", "description"],
94+
flattenNested: true,
95+
},
96+
});
97+
});
98+
99+
it("should throw error when legacy config is only partially set", () => {
100+
process.env.FIRESTORE_COLLECTION_PATH = "books";
101+
102+
expect(() => config.createCollectionConfigMap()).toThrow("Incomplete legacy collection config. Set both FIRESTORE_COLLECTION_PATH and TYPESENSE_COLLECTION_NAME");
103+
});
104+
105+
it("should throw error when multi-collection config is only partially set", () => {
106+
process.env.FIRESTORE_COLLECTION_PATHS = "users,products";
107+
108+
expect(() => config.createCollectionConfigMap()).toThrow("Incomplete multi-collection config. Set both FIRESTORE_COLLECTION_PATHS and TYPESENSE_COLLECTION_NAMES");
109+
});
110+
71111
it("should create collection map from legacy single collection parameters", () => {
72112
process.env.FIRESTORE_COLLECTION_PATH = "books";
73113
process.env.TYPESENSE_COLLECTION_NAME = "books";
@@ -114,6 +154,10 @@ describe("Multi-Collection Configuration", () => {
114154

115155
expect(() => config.createCollectionConfigMap()).toThrow("Mismatch in collection counts: 2 Firestore paths vs 1 Typesense names");
116156
});
157+
158+
it("should throw error when no collection config is provided", () => {
159+
expect(() => config.createCollectionConfigMap()).toThrow("No Firestore collection config found");
160+
});
117161
});
118162

119163
describe("collections property", () => {

0 commit comments

Comments
 (0)