Skip to content

Commit 7024bfa

Browse files
committed
elastic arrange with config
1 parent b433d97 commit 7024bfa

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/Contexts/Shared/infrastructure/persistence/elasticsearch/ElasticRepository.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export abstract class ElasticRepository<T extends AggregateRoot> {
1616
this.criteriaConverter = new ElasticCriteriaConverter();
1717
}
1818

19-
protected moduleName(): string {
19+
protected indexName(): string {
2020
return this.config.indexName;
2121
}
2222

@@ -41,7 +41,7 @@ export abstract class ElasticRepository<T extends AggregateRoot> {
4141

4242
try {
4343
const response = await client.search({
44-
index: this.moduleName(),
44+
index: this.indexName(),
4545
body: body.build()
4646
});
4747

@@ -62,6 +62,6 @@ export abstract class ElasticRepository<T extends AggregateRoot> {
6262
const client = await this.client();
6363
const document = { ...aggregateRoot.toPrimitives() };
6464

65-
await client.index({ index: this.moduleName(), body: document, refresh: 'wait_for' }); // wait_for wait for a refresh to make this operation visible to search
65+
await client.index({ index: this.indexName(), body: document, refresh: 'wait_for' }); // wait_for wait for a refresh to make this operation visible to search
6666
}
6767
}

src/apps/backoffice/backend/dependency-injection/application_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ imports:
44
services:
55
Backoffice.Backend.EnvironmentArranger:
66
class: ../../../../../tests/Contexts/Shared/infrastructure/elastic/ElasticEnvironmentArranger
7-
arguments: ['@Shared.ElasticConnectionManager']
7+
arguments: ['@Shared.ElasticConnectionManager', '@Backoffice.courses.ElasticConfig']
88

99
Shared.EventBus:
1010
class: ../../../../Contexts/Shared/infrastructure/EventBus/InMemory/InMemorySyncEventBus

tests/Contexts/Shared/infrastructure/elastic/ElasticEnvironmentArranger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { Client as ElasticClient } from '@elastic/elasticsearch';
2+
import ElasticConfig from '../../../../../src/Contexts/Shared/infrastructure/persistence/elasticsearch/ElasticConfig';
23
import { EnvironmentArranger } from '../arranger/EnvironmentArranger';
34

45
export class ElasticEnvironmentArranger extends EnvironmentArranger {
5-
constructor(private _client: Promise<ElasticClient>) {
6+
constructor(private _client: Promise<ElasticClient>, private config: ElasticConfig) {
67
super();
78
}
89

910
public async arrange(): Promise<void> {
10-
await this.dropAllIndex();
11+
await this.dropIndex(this.config.indexName);
1112
}
1213

13-
protected async dropAllIndex(): Promise<void> {
14+
protected async dropIndex(indexName: string): Promise<void> {
1415
const client = await this.client();
1516

1617
await client.deleteByQuery({
17-
index: 'backofficecourses-test',
18+
index: indexName,
1819
body: {
1920
query: {
2021
match_all: {}

0 commit comments

Comments
 (0)