Skip to content

Commit

Permalink
test(elasticsearch): use TestBed for service creation
Browse files Browse the repository at this point in the history
  • Loading branch information
fgravin committed Nov 3, 2023
1 parent e70070d commit 020fa07
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@ import { ElasticsearchService } from './elasticsearch.service'
import { ES_FIXTURE_AGGS_RESPONSE } from '@geonetwork-ui/common/fixtures'
import { LangService } from '@geonetwork-ui/util/i18n'
import { EsSearchParams } from '@geonetwork-ui/api/metadata-converter'
import { TestBed } from '@angular/core/testing'
import { METADATA_LANGUAGE } from '../../metadata-language'

const langServiceMock = {
iso3: 'eng',
} as LangService
class LangServiceMock {
iso3 = 'eng'
}

describe('ElasticsearchService', () => {
let service: ElasticsearchService
let searchFilters

beforeEach(() => {
service = new ElasticsearchService(langServiceMock, 'fre')
TestBed.configureTestingModule({
providers: [
{
provide: LangService,
useClass: LangServiceMock,
},
{
provide: METADATA_LANGUAGE,
useValue: 'fre',
},
],
})
service = TestBed.inject(ElasticsearchService)
})

it('should be created', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ export class ElasticsearchService {
}

private getQueryLang(): string {
return this.metadataLang
? this.isCurrentSearchLang()
if (this.metadataLang) {
return this.isCurrentSearchLang()
? `lang${this.lang3}`
: `lang${this.metadataLang}`
: `*`
} else return '*'
}
private isCurrentSearchLang() {
return this.metadataLang === 'current'
Expand Down

0 comments on commit 020fa07

Please sign in to comment.