Просмотр исходного кода

refactor: Export replaceMongoDbName function to eliminate code duplication

- Export replaceMongoDbName from mongoms.ts
- Import the function in the test file instead of duplicating code
- Improves maintainability and follows DRY principle

Co-authored-by: yuki-takei <1638767+yuki-takei@users.noreply.github.com>
copilot-swe-agent[bot] 2 месяцев назад
Родитель
Сommit
495743cf15
2 измененных файлов с 2 добавлено и 11 удалено
  1. 1 10
      apps/app/test/setup/mongoms.spec.ts
  2. 1 1
      apps/app/test/setup/mongoms.ts

+ 1 - 10
apps/app/test/setup/mongoms.spec.ts

@@ -1,15 +1,6 @@
-import ConnectionString from 'mongodb-connection-string-url';
 import { describe, expect, it } from 'vitest';
 import { describe, expect, it } from 'vitest';
 
 
-/**
- * Replace the database name in a MongoDB connection URI.
- * Uses mongodb-connection-string-url package for robust parsing.
- */
-function replaceMongoDbName(uri: string, newDbName: string): string {
-  const cs = new ConnectionString(uri);
-  cs.pathname = `/${newDbName}`;
-  return cs.href;
-}
+import { replaceMongoDbName } from './mongoms';
 
 
 describe('replaceMongoDbName', () => {
 describe('replaceMongoDbName', () => {
   describe('single-host URIs', () => {
   describe('single-host URIs', () => {

+ 1 - 1
apps/app/test/setup/mongoms.ts

@@ -15,7 +15,7 @@ let mongoServer: MongoMemoryServer | undefined;
  * @param newDbName - New database name to use
  * @param newDbName - New database name to use
  * @returns Modified URI with the new database name
  * @returns Modified URI with the new database name
  */
  */
-function replaceMongoDbName(uri: string, newDbName: string): string {
+export function replaceMongoDbName(uri: string, newDbName: string): string {
   const cs = new ConnectionString(uri);
   const cs = new ConnectionString(uri);
   cs.pathname = `/${newDbName}`;
   cs.pathname = `/${newDbName}`;
   return cs.href;
   return cs.href;