فهرست منبع

mock ldap.createClient

Futa Arai 2 سال پیش
والد
کامیت
c9bc0ece09
1فایلهای تغییر یافته به همراه5 افزوده شده و 7 حذف شده
  1. 5 7
      apps/app/test/integration/service/ldap-user-group-sync.test.ts

+ 5 - 7
apps/app/test/integration/service/ldap-user-group-sync.test.ts

@@ -1,9 +1,12 @@
+import ldap, { Client } from 'ldapjs';
+
 import LdapUserGroupSyncService from '../../../src/features/external-user-group/server/service/ldap-user-group-sync';
 import LdapUserGroupSyncService from '../../../src/features/external-user-group/server/service/ldap-user-group-sync';
 import { configManager } from '../../../src/server/service/config-manager';
 import { configManager } from '../../../src/server/service/config-manager';
 import LdapService from '../../../src/server/service/ldap';
 import LdapService from '../../../src/server/service/ldap';
 import PassportService from '../../../src/server/service/passport';
 import PassportService from '../../../src/server/service/passport';
 import { getInstance } from '../setup-crowi';
 import { getInstance } from '../setup-crowi';
 
 
+
 describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
 describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
   let crowi;
   let crowi;
   let ldapGroupSyncService: LdapUserGroupSyncService;
   let ldapGroupSyncService: LdapUserGroupSyncService;
@@ -22,13 +25,7 @@ describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
   jest.mock('../../../src/server/service/ldap');
   jest.mock('../../../src/server/service/ldap');
   const mockBind = jest.spyOn(LdapService.prototype, 'bind');
   const mockBind = jest.spyOn(LdapService.prototype, 'bind');
   const mockLdapSearch = jest.spyOn(LdapService.prototype, 'search');
   const mockLdapSearch = jest.spyOn(LdapService.prototype, 'search');
-
-  // mock LdapService constructor
-  const OriginalLdapService = { ...LdapService };
-  const mockConstructor = jest.fn(function(username, password) {
-    OriginalLdapService.constructor.call(this, 'Mocked LdapServer');
-  });
-  LdapService.prototype.constructor = mockConstructor;
+  const mockLdapCreateClient = jest.spyOn(ldap, 'createClient');
 
 
   beforeAll(async() => {
   beforeAll(async() => {
     crowi = await getInstance();
     crowi = await getInstance();
@@ -40,6 +37,7 @@ describe('LdapUserGroupSyncService.generateExternalUserGroupTrees', () => {
     mockBind.mockImplementation(() => {
     mockBind.mockImplementation(() => {
       return Promise.resolve();
       return Promise.resolve();
     });
     });
+    mockLdapCreateClient.mockImplementation(() => { return {} as Client });
   });
   });
 
 
   describe('When there is no circular reference in group tree', () => {
   describe('When there is no circular reference in group tree', () => {