Fix some more typesense client tests

This commit is contained in:
2026-01-15 09:35:17 +01:00
parent 75d29ca90a
commit 9ac085fe2c
2 changed files with 36 additions and 23 deletions

View File

@@ -9,7 +9,6 @@ describe('Typesense Client InvTypes', () => {
it('single type', async () => {
const result = await GetInvTypes([630]);
expect(result.size).toBe(1);
expect(result.get(630)).toBeDefined();
expect(fetchSpy).toHaveBeenCalledOnce();
@@ -217,7 +216,7 @@ describe('Typesense Client GetTypeCategories', () => {
expect(results.get(630)).toBeDefined();
expect(fetchSpy).toHaveBeenCalled();
});
it('get different categories from different type ids', async () => {
const results = await GetTypeCategories([450, 1829, 582]);
expect(results.size).toBe(3);
@@ -251,7 +250,7 @@ describe('Typesense Client AreTypesBlueprints', () => {
expect(results.get(582)).toBe(false);
expect(fetchSpy).toHaveBeenCalled();
});
it('type is blueprint', async () => {
const results = await AreTypesBlueprints([11135]);
expect(results.size).toBe(1);
@@ -341,12 +340,12 @@ describe('Typesense Client GetIndustryActivityProducts', () => {
const results = await GetIndustryActivityProducts([11135]);
if (results.size > 0) {
const product = results.get(11135);
if (product) {
expect(product).toHaveProperty('typeID');
expect(product).toHaveProperty('activityID');
expect(product).toHaveProperty('productTypeID');
expect(product).toHaveProperty('quantity');
}
expect(product).toBeDefined();
expect(product?.length).toBe(1);
expect(product?.[0]).toHaveProperty('typeID');
expect(product?.[0]).toHaveProperty('activityID');
expect(product?.[0]).toHaveProperty('productTypeID');
expect(product?.[0]).toHaveProperty('quantity');
}
});
});
@@ -414,12 +413,12 @@ describe('Typesense Client GetIndustryActivityMaterials', () => {
const results = await GetIndustryActivityMaterials([11135]);
if (results.size > 0) {
const material = results.get(11135);
if (material) {
expect(material).toHaveProperty('typeID');
expect(material).toHaveProperty('activityID');
expect(material).toHaveProperty('materialTypeID');
expect(material).toHaveProperty('quantity');
}
expect(material).toBeDefined();
expect(material?.length).toBe(1);
expect(material?.[0]).toHaveProperty('typeID');
expect(material?.[0]).toHaveProperty('activityID');
expect(material?.[0]).toHaveProperty('materialTypeID');
expect(material?.[0]).toHaveProperty('quantity');
}
});
});

View File

@@ -42,7 +42,7 @@ async function Get<T>(ids: number[], collection: string, id_key: string): Promis
reqBatches.push(batch);
}
console.log("reqBatches", reqBatches);
// console.log("reqBatches", reqBatches);
// Fetch the batches
await Promise.all(
reqBatches.map(async (batch) => {
@@ -72,24 +72,37 @@ async function Get<T>(ids: number[], collection: string, id_key: string): Promis
return Promise.resolve(resp);
}
function flatMap<T>(inMap: Map<number, T[]>): Map<number, T | null> {
const resp = new Map<number, T | null>();
for (const [id, value] of inMap.entries())
resp.set(id, value[0] ?? null);
return resp;
}
// A bit of a mess... But it'll do for now, until I get a better idea
export async function GetInvTypes(typeIds: number[]): Promise<Map<number, InvType | null>> {
return (await Get<InvType>(typeIds, "invTypes", "typeID"))[0] ?? null;
const result = await Get<InvType>(typeIds, "invTypes", "typeID");
return flatMap<InvType>(result);
}
export async function GetInvGroups(groupIds: number[]): Promise<Map<number, InvGroup | null>> {
return (await Get<InvGroup>(groupIds, "invGroups", "groupID"))[0] ?? null;
const result = await Get<InvGroup>(groupIds, "invGroups", "groupID");
return flatMap<InvGroup>(result);
}
export async function GetInvCategories(categoryIds: number[]): Promise<Map<number, InvCategory | null>> {
return (await Get<InvCategory>(categoryIds, "invCategories", "categoryID"))[0] ?? null;
const result = await Get<InvCategory>(categoryIds, "invCategories", "categoryID");
return flatMap<InvCategory>(result);
}
export async function GetRAMActivities(activityIds: number[]): Promise<Map<number, RAMActivity | null>> {
return (await Get<RAMActivity>(activityIds, "ramActivities", "activityID"))[0] ?? null;
const result = await Get<RAMActivity>(activityIds, "ramActivities", "activityID");
return flatMap<RAMActivity>(result);
}
export async function GetStaStations(stationIds: number[]): Promise<Map<number, StaStation | null>> {
return (await Get<StaStation>(stationIds, "staStations", "stationID"))[0] ?? null;
const result = await Get<StaStation>(stationIds, "staStations", "stationID");
return flatMap<StaStation>(result);
}
export async function GetIndustryActivityProducts(typeIds: number[]): Promise<Map<number, IndustryActivityProduct[]>> {
@@ -100,8 +113,9 @@ export async function GetIndustryActivityMaterials(typeIds: number[]): Promise<M
return await Get<IndustryActivityMaterial>(typeIds, "industryActivityMaterials", "typeID");
}
export async function GetIndustryActivity(typeIds: number[]): Promise<Map<number, IndustryActivity[]>> {
return await Get<IndustryActivity>(typeIds, "industryActivity", "typeID");
export async function GetIndustryActivity(typeIds: number[]): Promise<Map<number, IndustryActivity | null>> {
const result = await Get<IndustryActivity>(typeIds, "industryActivity", "typeID");
return flatMap<IndustryActivity>(result);
}
async function queryTypesense<T>(params: URLSearchParams, collection: string): Promise<TypesenseResponse<T>> {