Skip to content

Commit

Permalink
fix: better seed
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanYadaev committed Jan 23, 2025
1 parent 54eb777 commit 7e1b56d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 300 deletions.
2 changes: 1 addition & 1 deletion services/workflows-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"test:integration": "jest --testRegex '.*\\.intg\\.test\\.ts$'",
"test:e2e": "jest --testRegex '.*\\.e2e\\.test\\.ts$'",
"test:watch": "jest --verbose --watch",
"seed": "tsx scripts/seed.ts",
"seed": "nest start --entryFile scripts/seed",
"db:migrate-dev": "prisma migrate dev",
"db:migrate-up": "prisma migrate deploy",
"db:clean": "tsx scripts/clean.ts",
Expand Down
2 changes: 0 additions & 2 deletions services/workflows-service/scripts/run-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export async function fliterQuery() {
id: true,
email: true,
phone: true,
jsonData: true,
lastName: true,
avatarUrl: true,
createdAt: true,
Expand All @@ -31,7 +30,6 @@ export async function fliterQuery() {
approvalState: true,
correlationId: true,
additionalInfo: true,
verificationId: true,
workflowRuntimeData: {
select: {
id: true,
Expand Down
44 changes: 37 additions & 7 deletions services/workflows-service/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import { generateKycManualReviewRuntimeAndToken } from './workflows/runtime/gene
import { generateInitialCollectionFlowExample } from './workflows/runtime/generate-initial-collection-flow-example';
import { uiKybParentWithAssociatedCompanies } from './workflows/ui-definition/kyb-with-associated-companies/ui-kyb-parent-dynamic-example';
import { generateWebsiteMonitoringExample } from './workflows/website-monitoring-workflow';
import { CustomerService } from '@/customer/customer.service';
import { NestFactory } from '@nestjs/core';
import { AppModule } from '@/app.module';

const BCRYPT_SALT: string | number = 10;

Expand Down Expand Up @@ -69,14 +72,14 @@ function generateAvatarImageUri(imageTemplate: string, countOfBusiness: number,
}

async function createCustomer(
client: PrismaClient,
customerService: CustomerService,
id: string,
apiKey: string,
logoImageUri: string,
faviconImageUri: string,
webhookSharedSecret: string,
) {
return client.customer.create({
return customerService.create({
data: {
id: `customer-${id}`,
name: `customer-${id}`,
Expand All @@ -93,9 +96,28 @@ async function createCustomer(
faviconImageUri,
country: 'GB',
language: 'en',
config: {
isMerchantMonitoringEnabled: true,
isExample: true,
config: { isDemo: true, withQualityControl: true, isMerchantMonitoringEnabled: true },
features: {
createBusinessReport: {
enabled: true,
options: { type: 'MERCHANT_REPORT_T1', version: '2' },
},
createBusinessReportBatch: {
enabled: true,
options: { type: 'MERCHANT_REPORT_T1', version: '2' },
},
ONGOING_MERCHANT_REPORT: {
name: 'ONGOING_MERCHANT_REPORT',
enabled: true,
options: {
reportType: 'ONGOING_MERCHANT_REPORT_T1',
runByDefault: true,
scheduleType: 'interval',
intervalInDays: 30,
proxyViaCountry: 'GB',
workflowVersion: '2',
},
},
},
},
});
Expand All @@ -120,10 +142,16 @@ const DEFAULT_TOKENS = {

async function seed() {
console.info('Seeding database...');
const app = await NestFactory.createApplicationContext(AppModule, { logger: false });

app.enableShutdownHooks();

const customerService = app.get(CustomerService);

const client = new PrismaClient();
await generateDynamicDefinitionForE2eTest(client);
const customer = (await createCustomer(
client,
customerService,
'1',
env.API_KEY,
'https://cdn.ballerine.io/images/ballerine_logo.svg',
Expand All @@ -132,7 +160,7 @@ async function seed() {
)) as Customer;

const customer2 = (await createCustomer(
client,
customerService,
'2',
`${env.API_KEY}2`,
'https://cdn.ballerine.io/images/ballerine_logo.svg',
Expand Down Expand Up @@ -1044,6 +1072,8 @@ async function seed() {
token: DEFAULT_TOKENS.KYC,
});

await app.close();

console.info('Seeded database successfully');
}
async function createUsers({ project1, project2 }: any, client: PrismaClient) {
Expand Down
Loading

0 comments on commit 7e1b56d

Please sign in to comment.