Skip to content

Commit

Permalink
feat: add util registerModel in test
Browse files Browse the repository at this point in the history
  • Loading branch information
loopingz committed Nov 29, 2023
1 parent ed1429f commit 059eee8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/core/src/test.ts
Expand Up @@ -3,7 +3,16 @@ import { execSync } from "child_process";
import { existsSync, unlinkSync } from "fs";
import * as path from "path";
import { register } from "prom-client";
import { Core, HttpContext, HttpMethodType, MemoryStore, Service, UuidModel, WebContext } from "./index";
import {
Core,
CoreModelDefinition,
HttpContext,
HttpMethodType,
MemoryStore,
Service,
UuidModel,
WebContext
} from "./index";
import { PrometheusService } from "./services/prometheus";
import { ConsoleLoggerService } from "./utils/logger";
import { FileUtils } from "./utils/serializers";
Expand Down Expand Up @@ -449,6 +458,15 @@ class WebdaTest {
this.webda.services[name] = service;
return service;
}

/**
* Dynamic add a model to webda
* @param model
* @param klass
*/
registerModel<T extends CoreModelDefinition>(model: T, name: string = model.constructor.name) {
this.webda.getApplication().addModel(name, model);
}
}

class WebdaSimpleTest extends WebdaTest {
Expand Down

0 comments on commit 059eee8

Please sign in to comment.