forked from Yara724/api
Compare commits
3
Commits
63b1bb3e2c
...
e56e697e4f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e56e697e4f | ||
|
|
ebd2b62297
|
||
|
|
69a9fc351c |
@@ -7,6 +7,9 @@ when:
|
||||
branch: main
|
||||
- event: manual
|
||||
|
||||
labels:
|
||||
hostname: build-node-01
|
||||
|
||||
skip_clone: true
|
||||
|
||||
variables:
|
||||
|
||||
@@ -177,9 +177,11 @@ export const SEED_FANAVARAN_CLIENT_PROFILES: Record<
|
||||
contractId: "304",
|
||||
location: "1",
|
||||
},
|
||||
// Expert role ids not confirmed for Moallem yet — start from shared shape.
|
||||
defaults: {
|
||||
...SHARED_FANAVARAN_DEFAULTS,
|
||||
// GEN.03 financial case owner / GEN.08 third-party financial assessor.
|
||||
ClaimExpertId: 5347,
|
||||
ExpertiseClaimExpertId: 5350,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -96,6 +96,16 @@ export const FANAVARAN_REMOTE_LOOKUPS: FanavaranRemoteLookupDefinition[] = [
|
||||
url: `${FANAVARAN_LOOKUP_BASE_URL}/car/base-info/vehicle-kinds`,
|
||||
cacheFile: "vehicle-kinds.json",
|
||||
},
|
||||
{
|
||||
name: "notifier-type",
|
||||
url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/notifier-type`,
|
||||
cacheFile: "notifier-type.json",
|
||||
},
|
||||
{
|
||||
name: "notifier-relation",
|
||||
url: `${FANAVARAN_LOOKUP_BASE_URL}/car/code-list/notifier-relation`,
|
||||
cacheFile: "notifier-relation.json",
|
||||
},
|
||||
{
|
||||
name: "person-role",
|
||||
url: `${FANAVARAN_LOOKUP_BASE_URL}/common/code-list/person-role`,
|
||||
|
||||
@@ -142,7 +142,7 @@ export class FanavaranLookupService {
|
||||
/**
|
||||
* Resolve a remote Fanavaran lookup.
|
||||
*
|
||||
* Parsian (default): file → `lookups` collection → Fanavaran API
|
||||
* Parsian (default): `lookups` collection → file → Fanavaran API
|
||||
* Tejaratno with dbSource: file → Fanavaran → DB on API failure
|
||||
* Others: file → Fanavaran
|
||||
*/
|
||||
@@ -155,7 +155,7 @@ export class FanavaranLookupService {
|
||||
| {
|
||||
/** Soft/hard DB read — return null/undefined to miss. */
|
||||
dbSource?: () => Promise<unknown | null | undefined>;
|
||||
/** When true: try DB after file miss, before Fanavaran. */
|
||||
/** When true: try DB before the cache file and Fanavaran. */
|
||||
preferDbBeforeRemote?: boolean;
|
||||
},
|
||||
): Promise<unknown> {
|
||||
@@ -173,11 +173,6 @@ export class FanavaranLookupService {
|
||||
? () => this.readLookupsCollectionByCacheFile(cacheFile)
|
||||
: undefined);
|
||||
|
||||
const cached = await this.readCacheFile(clientKey, cacheFile);
|
||||
if (cached !== null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
if (preferDbBeforeRemote && dbSource) {
|
||||
const fromDb = await this.tryDbSource(clientKey, cacheFile, dbSource);
|
||||
if (fromDb !== null) {
|
||||
@@ -186,6 +181,11 @@ export class FanavaranLookupService {
|
||||
}
|
||||
}
|
||||
|
||||
const cached = await this.readCacheFile(clientKey, cacheFile);
|
||||
if (cached !== null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
try {
|
||||
const tenantUrl = url.replace(
|
||||
FANAVARAN_LOOKUP_BASE_URL,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { LookupsService } from "src/lookups/lookups.service";
|
||||
import { toFanavaranHullBaseClaimPayload } from "src/claim-request-management/fanavaran-hull-base-claim";
|
||||
import {
|
||||
@@ -8,34 +7,61 @@ import {
|
||||
|
||||
describe("TejaratNo notifier contract", () => {
|
||||
it.each(["notifier-type", "notifier-relation"])(
|
||||
"reads %s from the lookups collection and does not call Fanavaran",
|
||||
"falls through to Fanavaran for %s when the lookups collection has no row",
|
||||
async (name) => {
|
||||
const stored = tejaratNotifierLookup(name);
|
||||
const remote = tejaratNotifierLookup(name);
|
||||
const service = Object.create(LookupsService.prototype) as any;
|
||||
service.activeClientKey = jest.fn().mockReturnValue("tejaratno");
|
||||
service.fanavaranLookupService = {
|
||||
getRemoteLookup: jest.fn(),
|
||||
readStoredLookup: jest.fn().mockResolvedValue(stored),
|
||||
getRemoteLookup: jest
|
||||
.fn()
|
||||
.mockImplementation(async (_client, _url, _cache, options) => {
|
||||
const stored = await options.dbSource();
|
||||
return stored ?? remote;
|
||||
}),
|
||||
readStoredLookup: jest.fn().mockResolvedValue(null),
|
||||
};
|
||||
service.lookupDbService = {
|
||||
findOne: jest.fn().mockResolvedValue(null),
|
||||
findOneAndUpdate: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const result = await service.getClientRemoteLookup(name);
|
||||
expect(result).toEqual(stored);
|
||||
expect(result).toEqual(remote);
|
||||
expect(service.fanavaranLookupService.readStoredLookup).toHaveBeenCalledWith(
|
||||
name,
|
||||
);
|
||||
expect(
|
||||
service.fanavaranLookupService.getRemoteLookup,
|
||||
).not.toHaveBeenCalled();
|
||||
).toHaveBeenCalledWith(
|
||||
"tejaratno",
|
||||
expect.stringContaining(`/car/code-list/${name}`),
|
||||
`${name}.json`,
|
||||
expect.objectContaining({ preferDbBeforeRemote: true }),
|
||||
);
|
||||
expect(service.lookupDbService.findOneAndUpdate).toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["parsian", "moallem"])(
|
||||
"rejects the tenant-specific lookups for %s",
|
||||
"also requests %s notifier lookups from Fanavaran on a DB miss",
|
||||
async (clientKey) => {
|
||||
const service = Object.create(LookupsService.prototype) as any;
|
||||
service.activeClientKey = jest.fn().mockReturnValue(clientKey);
|
||||
await expect(
|
||||
service.getClientRemoteLookup("notifier-type"),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
service.fanavaranLookupService = {
|
||||
getRemoteLookup: jest
|
||||
.fn()
|
||||
.mockImplementation(async (_client, _url, _cache, options) => {
|
||||
const stored = await options.dbSource();
|
||||
return stored ?? [];
|
||||
}),
|
||||
readStoredLookup: jest.fn().mockResolvedValue(null),
|
||||
};
|
||||
service.lookupDbService = {
|
||||
findOne: jest.fn().mockResolvedValue(null),
|
||||
findOneAndUpdate: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
await service.getClientRemoteLookup("notifier-type");
|
||||
expect(service.fanavaranLookupService.getRemoteLookup).toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -671,7 +671,7 @@ export class LookupsController {
|
||||
description:
|
||||
"Generic cached Fanavaran lookup fetcher. Configured names use their catalogue URL; " +
|
||||
"unlisted slugs (e.g. vehicle-groups) fall back to car/base-info/{lookupName}. " +
|
||||
"TejaratNo notifier-type and notifier-relation are read from the lookups collection and are not fetched from Fanavaran.",
|
||||
"Notifier lookups check the lookups collection first for every tenant, then fetch from Fanavaran on a miss.",
|
||||
})
|
||||
@ApiParam({
|
||||
name: "lookupName",
|
||||
|
||||
@@ -136,30 +136,20 @@ export class LookupsService implements OnModuleInit, OnModuleDestroy {
|
||||
|
||||
async getClientRemoteLookup(lookupName: string): Promise<unknown> {
|
||||
const clientKey = this.activeClientKey();
|
||||
if (isTejaratNotifierLookup(lookupName)) {
|
||||
if (clientKey !== "tejaratno") {
|
||||
throw new BadRequestException("Notifier lookups apply only to TejaratNo.");
|
||||
}
|
||||
const stored = await this.fanavaranLookupService.readStoredLookup(lookupName);
|
||||
if (stored == null) {
|
||||
throw new NotFoundException(`Lookup "${lookupName}" not found`);
|
||||
}
|
||||
return stored;
|
||||
}
|
||||
const definition = this.findRemoteLookup(lookupName);
|
||||
|
||||
// Parsian: file → lookups collection → Fanavaran (default inside FanavaranLookupService)
|
||||
// Tejaratno: file → Fanavaran → DB on API failure
|
||||
// readStoredLookup returns null when the row is missing, so a Fanavaran
|
||||
// failure is not replaced by "Lookup not found".
|
||||
// Notifier lookups check the shared DB seed before Fanavaran for every
|
||||
// tenant. A DB miss proceeds to Fanavaran and the response is cached below.
|
||||
// Other lookups retain their configured tenant-specific fallback order.
|
||||
const data = await this.fanavaranLookupService.getRemoteLookup(
|
||||
clientKey,
|
||||
definition.url,
|
||||
definition.cacheFile,
|
||||
clientKey === "tejaratno"
|
||||
isTejaratNotifierLookup(lookupName)
|
||||
? {
|
||||
dbSource: () =>
|
||||
this.fanavaranLookupService.readStoredLookup(lookupName),
|
||||
preferDbBeforeRemote: true,
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user