Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add exactBandMatch as default false in searchAdvancedBand #15

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/clients/metalArchives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { FastifyInstance } from 'fastify'
import { searchBandAdvanced } from './searchBandAdvanced'

export const createMetalArchivesClient = (_fastify: FastifyInstance) => ({
searchBand: async (band: string, offset: number = 0) => {
return searchBandAdvanced(band, offset, true, {})
searchBand: async (
band: string,
exactBandMatch: boolean,
offset: number = 0
) => {
return searchBandAdvanced(band, offset, exactBandMatch, {})
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/clients/metalArchives/searchBandAdvanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const searchBandAdvanced = async (
} = advancedSearchData

const conditionalParameters = {
...(exactBandMatch && { exactBandMatch }),
...(advancedSearchData.genre && { genre: advancedSearchData.genre }),
...(advancedSearchData.country && {
country: advancedSearchData.country
Expand All @@ -62,7 +63,6 @@ export const searchBandAdvanced = async (
url: config.metalArchives.searchBandAdvancedUrl,
params: {
bandName: band,
exactBandMatch,
status,
themes,
location,
Expand Down
3 changes: 1 addition & 2 deletions src/clients/metalArchives/test/searchBandAdvanced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ describe('searchBandAdvanced', () => {
url: 'https://mock-api.com/search',
params: {
...searchBandAdvancedQueryFixture,
bandName: '',
exactBandMatch: false
bandName: ''
giacomocamerano marked this conversation as resolved.
Show resolved Hide resolved
}
})
})
Expand Down
8 changes: 6 additions & 2 deletions src/routes/bands/handlers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { ServiceInfoRoutesOptions } from '../index'
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'

const searchBand = async (data: SearchBandQuery, fastify: FastifyInstance) => {
const { band, offset } = data
const { band, exactBandMatch, offset } = data

const { countTotal, countCurrent, results } =
await fastify.metalArchives.searchBand(band, offset)
await fastify.metalArchives.searchBand(
band,
exactBandMatch ?? false,
offset
)

return {
search: band,
Expand Down
15 changes: 15 additions & 0 deletions src/routes/bands/handlers/test/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ describe('Search Band', () => {
expect(nock.isDone()).toBe(true)
})

it('Should return search results, supply bandname, offset and exactBandMatch', async () => {
nock(config.metalArchives.searchBandAdvancedUrl)
.get('/')
.query(true)
.reply(200, searchBandAdvancedResponseFixture)

const response = await server.inject({
method: 'GET',
url: '/bands/search/?band=immortal&offset=0&exactBandMatch=true'
})

expect(response.statusCode).toEqual(200)
expect(nock.isDone()).toBe(true)
})
giacomocamerano marked this conversation as resolved.
Show resolved Hide resolved

it('Should handle empty band name', async () => {
const response = await server.inject({
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion src/routes/bands/schema/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { bandSearchResultSchema } from '@src/shared/schema'

export const searchBandQuerySchema = Type.Object({
band: Type.String({ minLength: 1 }),
offset: Type.Optional(Type.Number({ minimum: 0 }))
offset: Type.Optional(Type.Number({ minimum: 0 })),
exactBandMatch: Type.Optional(Type.Boolean())
giacomocamerano marked this conversation as resolved.
Show resolved Hide resolved
})

export type SearchBandQuery = Static<typeof searchBandQuerySchema>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {

export const searchBandAdvancedQueryFixture = {
bandName: `immortal`,
exactBandMatch: true,
status: [1, 2, 3, 4, 5, 6],
themes: '*',
location: '*',
Expand Down