Skip to content

Commit

Permalink
Test QuestionService y modificación git actions
Browse files Browse the repository at this point in the history
  • Loading branch information
UO285267 committed Mar 7, 2024
1 parent 739d795 commit a6a49d1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix preguntas/generatorservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix preguntas/generatorservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
Expand Down
22 changes: 21 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix preguntas/generatorservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix preguntas/generatorservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
Expand All @@ -35,6 +37,7 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice install
- run: npm --prefix users/userservice install
- run: npm --prefix preguntas/generatorservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
Expand Down Expand Up @@ -93,6 +96,23 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/userservice
docker-push-generatorservice:
name: Push generator service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es3a/generatorservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: preguntas/generatorservice
docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -113,7 +133,7 @@ jobs:
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp]
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-generatorservice,docker-push-webapp]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ services:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb
MONGODB_URI1: mongodb://localhost:27017/templatedb
userservice:
container_name: userservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es3a/userservice:latest
Expand Down
47 changes: 47 additions & 0 deletions preguntas/generatorservice/question-service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');

const Template = require('./template-model');

let app;
let mongoServer;
const template = {
question: "¿Cuál es la capital de ^ ?",
query: "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P36 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }",

}

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
app = require('./question-service');

await addTemplate(template);
});

//Function to add template
async function addTemplate(template){
const newTemplate = new Template({
question: template.question,
query: template.query,
});

await newTemplate.save();
}

afterAll(async () => {
app.close();
await mongoServer.stop();
});

describe('Question Service', () => {
it('should generate and store a question', async () => {
const response = await request(app).get('/generate-question');
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('question');
expect(response.body).toHaveProperty('correctAnswer');
expect(response.body).toHaveProperty('allAnswers');
expect(response.body.allAnswers).toHaveLength(4);
});
});

0 comments on commit a6a49d1

Please sign in to comment.