Skip to content

Commit

Permalink
another attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-qg committed May 2, 2024
1 parent c245058 commit a4788c8
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
122 changes: 122 additions & 0 deletions questionsservice/wikidataExtractor/wikidataextractor-service.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit a4788c8

Please sign in to comment.