From a4788c8cd547d9c7bad473d3d511a4bfcbee1e80 Mon Sep 17 00:00:00 2001 From: Marco Quintana Date: Thu, 2 May 2024 18:22:11 +0200 Subject: [PATCH] another attempt --- .github/workflows/release.yml | 7 +- .../wikidataextractor-service.test.js | 122 ++++++++++++++++++ 2 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 questionsservice/wikidataExtractor/wikidataextractor-service.test.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 492a10c8..338bbbea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -75,10 +75,11 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: webapp - buildargs: | - API_URI1=http://${{ secrets.DEPLOY_HOST }}:8000 - API_URI2=http://${{ secrets.DEPLOY_HOST }}:8100 + buildargs: API_URI1, API_URI2 platforms: linux/arm64 + env: + API_URI1: http://${{ secrets.DEPLOY_HOST }}:8000 + API_URI2: http://${{ secrets.DEPLOY_HOST }}:8100 docker-push-authservice: name: Push auth service Docker Image to GitHub Packages runs-on: ubuntu-latest diff --git a/questionsservice/wikidataExtractor/wikidataextractor-service.test.js b/questionsservice/wikidataExtractor/wikidataextractor-service.test.js new file mode 100644 index 00000000..ee72d5a8 --- /dev/null +++ b/questionsservice/wikidataExtractor/wikidataextractor-service.test.js @@ -0,0 +1,122 @@ +import { + Pais, + Monumento, + Elemento, + Pelicula, + Cancion +} from './wikidataextractor-service'; + +describe('Wikidata Extractor Service', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe('Templates', () => { + const mockTransactions = [{ updateOne: jest.fn() }]; + + const mockWikiQueries = { + obtenerPaisYCapital: jest.fn(), + obtenerPaisYContinente: jest.fn(), + obtenerMonumentoYPais: jest.fn(), + obtenerSimboloQuimico: jest.fn(), + obtenerPeliculaYDirector: jest.fn(), + obtenerCancionYArtista: jest.fn() + }; + + const mockData = { + countryLabel: 'Country', + capitalLabel: 'Capital', + continentLabel: 'Continent', + monumentLabel: 'Monument', + elementLabel: 'Element', + symbol: 'Symbol', + peliculaLabel: 'Movie', + directorLabel: 'Director', + songLabel: 'Song', + artistLabel: 'Artist' + }; + + const mockSaveMethod = jest.fn(); + + const templates = [ + { + extractMethod: mockWikiQueries.obtenerPaisYCapital, + filtro: (element) => ({ pais: String(element.countryLabel) }), + campo_actualizar: (element) => ({ capital: element.capitalLabel }), + saveMethod: mockSaveMethod + }, + { + extractMethod: mockWikiQueries.obtenerPaisYContinente, + filtro: (element) => ({ pais: String(element.countryLabel) }), + campo_actualizar: (element) => ({ continente: element.continentLabel }), + saveMethod: mockSaveMethod + }, + { + extractMethod: mockWikiQueries.obtenerMonumentoYPais, + filtro: (element) => ({ monumento: String(element.monumentLabel) }), + campo_actualizar: (element) => ({ pais: element.countryLabel }), + saveMethod: mockSaveMethod + }, + { + extractMethod: mockWikiQueries.obtenerSimboloQuimico, + filtro: (element) => ({ elemento: String(element.elementLabel) }), + campo_actualizar: (element) => ({ simbolo: element.symbol }), + saveMethod: mockSaveMethod + }, + { + extractMethod: mockWikiQueries.obtenerPeliculaYDirector, + filtro: (element) => ({ pelicula: String(element.peliculaLabel) }), + campo_actualizar: (element) => ({ director: element.directorLabel }), + saveMethod: mockSaveMethod + }, + { + extractMethod: mockWikiQueries.obtenerCancionYArtista, + filtro: (element) => ({ cancion: String(element.songLabel) }), + campo_actualizar: (element) => ({ artista: element.artistLabel }), + saveMethod: mockSaveMethod + } + ]; + + test('Template 1', async () => { + mockWikiQueries.obtenerPaisYCapital.mockResolvedValue(mockData); + await templates[0].extractMethod(); + expect(mockWikiQueries.obtenerPaisYCapital).toHaveBeenCalled(); + expect(mockSaveMethod).toHaveBeenCalledWith(mockTransactions); + }); + + test('Template 2', async () => { + mockWikiQueries.obtenerPaisYContinente.mockResolvedValue(mockData); + await templates[1].extractMethod(); + expect(mockWikiQueries.obtenerPaisYContinente).toHaveBeenCalled(); + expect(mockSaveMethod).toHaveBeenCalledWith(mockTransactions); + }); + + test('Template 3', async () => { + mockWikiQueries.obtenerMonumentoYPais.mockResolvedValue(mockData); + await templates[2].extractMethod(); + expect(mockWikiQueries.obtenerMonumentoYPais).toHaveBeenCalled(); + expect(mockSaveMethod).toHaveBeenCalledWith(mockTransactions); + }); + + test('Template 4', async () => { + mockWikiQueries.obtenerSimboloQuimico.mockResolvedValue(mockData); + await templates[3].extractMethod(); + expect(mockWikiQueries.obtenerSimboloQuimico).toHaveBeenCalled(); + expect(mockSaveMethod).toHaveBeenCalledWith(mockTransactions); + }); + + test('Template 5', async () => { + mockWikiQueries.obtenerPeliculaYDirector.mockResolvedValue(mockData); + await templates[4].extractMethod(); + expect(mockWikiQueries.obtenerPeliculaYDirector).toHaveBeenCalled(); + expect(mockSaveMethod).toHaveBeenCalledWith(mockTransactions); + }); + + test('Template 6', async () => { + mockWikiQueries.obtenerCancionYArtista.mockResolvedValue(mockData); + await templates[5].extractMethod(); + expect(mockWikiQueries.obtenerCancionYArtista).toHaveBeenCalled(); + expect(mockSaveMethod).toHaveBeenCalledWith(mockTransactions); + }); + }); +}); \ No newline at end of file