Skip to content

Commit d6c36af

Browse files
committed
fix(search): fix tests
1 parent 82d4338 commit d6c36af

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/resources/resources.service.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ResourcesService {
2424
return [];
2525
}
2626
const resources = await this.getParentResources(namespaceId, resourceId);
27-
if (!resources) {
27+
if (resources.length === 0) {
2828
throw new NotFoundException('Resource not found');
2929
}
3030
return resources;
@@ -34,11 +34,8 @@ export class ResourcesService {
3434
namespaceId: string,
3535
resourceId: string | null,
3636
): Promise<ResourceMetaDto[]> {
37-
if (!resourceId) {
38-
return [];
39-
}
4037
const resources: Resource[] = [];
41-
while (true) {
38+
while (resourceId) {
4239
const resource = await this.resourceRepository.findOne({
4340
select: [
4441
'id',
@@ -55,9 +52,6 @@ export class ResourcesService {
5552
return [];
5653
}
5754
resources.push(resource);
58-
if (!resource.parentId) {
59-
break;
60-
}
6155
resourceId = resource.parentId;
6256
}
6357
return resources.map((r) => ResourceMetaDto.fromEntity(r));

src/search/search.e2e-spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ConfigService } from '@nestjs/config';
1717
import { getRepositoryToken } from '@nestjs/typeorm';
1818
import { WizardTaskService } from 'omniboxd/tasks/wizard-task.service';
1919
import { Task } from 'omniboxd/tasks/tasks.entity';
20+
import { ResourcesService } from 'omniboxd/resources/resources.service';
2021

2122
// Set environment variable to avoid the error in SearchService constructor
2223
process.env.OBB_WIZARD_BASE_URL = 'http://localhost:8000';
@@ -111,6 +112,12 @@ describe('SearchController (e2e)', () => {
111112
listAllResources: jest.fn().mockResolvedValue([]),
112113
},
113114
},
115+
{
116+
provide: ResourcesService,
117+
useValue: {
118+
getParentResources: jest.fn().mockResolvedValue([]),
119+
},
120+
},
114121
{
115122
provide: MessagesService,
116123
useValue: {

src/search/search.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ConversationsModule } from 'omniboxd/conversations/conversations.module
1111
import { TypeOrmModule } from '@nestjs/typeorm';
1212
import { Task } from 'omniboxd/tasks/tasks.entity';
1313
import { TasksModule } from 'omniboxd/tasks/tasks.module';
14+
import { ResourcesModule } from 'omniboxd/resources/resources.module';
1415

1516
@Module({
1617
exports: [SearchService],
@@ -19,6 +20,7 @@ import { TasksModule } from 'omniboxd/tasks/tasks.module';
1920
imports: [
2021
PermissionsModule,
2122
NamespaceResourcesModule,
23+
ResourcesModule,
2224
MessagesModule,
2325
ConversationsModule,
2426
TasksModule,

0 commit comments

Comments
 (0)