diff --git a/.github/workflows/build-publish-to-registry.yml b/.github/workflows/build-publish-to-registry.yml new file mode 100644 index 0000000..0191790 --- /dev/null +++ b/.github/workflows/build-publish-to-registry.yml @@ -0,0 +1,42 @@ +name: Publish to Docker +on: + push: + branches: + - main + - ci +permissions: + packages: write +jobs: + publish: + runs-on: ubuntu-latest$ + services: + mongodb: + image: mongo + ports: + - 27017:27017 + steps: + - name: Checkout + uses: actions/checkout@v4 + # Add your test steps here if needed... + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=sha + type=semver,pattern={{version}} + dev-latest + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build container + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ steps.meta.outputs.tags }} \ No newline at end of file diff --git a/.github/workflows/run-unit-tests-on-pr.yml b/.github/workflows/run-unit-tests-on-pr.yml new file mode 100644 index 0000000..407f6a3 --- /dev/null +++ b/.github/workflows/run-unit-tests-on-pr.yml @@ -0,0 +1,48 @@ +name: Run pnpm tests + +on: + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + services: + mongodb: + image: mongo + ports: + - 27017:27017 + steps: + - uses: actions/checkout@v2 + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '18.15' + + - name: Install pnpm + run: npm install -g pnpm + + - name: Install dependencies + run: pnpm install + - name: output list of files + run: ls -la reference-models/src/references + - name: Seed the database + run: pnpm db:init + env: + MONGO_HOST: localhost + MONGO_PORT: 27017 + MONGO_DATABASE: catalog-registry + API_KEY: 8904a5a5-24f1-45a1-be87-2984f703ed19 + API_URL: http://localhost:3000/v1 + PORT: 3000 + JOB_TIMEZONE: Europe/Paris + - name: Run tests + run: pnpm test + env: + MONGO_HOST: localhost + MONGO_PORT: 27017 + MONGO_DATABASE: catalog-registry + API_KEY: 8904a5a5-24f1-45a1-be87-2984f703ed19 + API_URL: http://localhost:3000/v1 + PORT: 3000 + JOB_TIMEZONE: Europe/Paris \ No newline at end of file diff --git a/.gitignore b/.gitignore index 86e7582..67f5317 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ dist reference-models/ .env static/ -.idea/ \ No newline at end of file +.idea/ + +*.iml \ No newline at end of file diff --git a/scripts/dbUpdate.js b/scripts/dbUpdate.js index 799a048..a301c9f 100644 --- a/scripts/dbUpdate.js +++ b/scripts/dbUpdate.js @@ -86,7 +86,7 @@ mongoose const processFiles = files.map(async (file) => { const filePath = path.join(directoryPath, file); - + console.log(`Processing file ${filePath}`) try { // Read the JSON-LD file content const fileContent = await fs.promises.readFile(filePath, "utf8"); diff --git a/tests/api.spec.ts b/tests/api.spec.ts index 3ada88a..506aa4d 100644 --- a/tests/api.spec.ts +++ b/tests/api.spec.ts @@ -149,7 +149,7 @@ describe("API Tests", () => { describe("GET /v1/jobs/:job - API KEY error", () => { it("should respond with code 400 and Header error", async () => { - const response = await request(app).get(`/v1/jobs/dbUpdateJob`); + const response = await request(app).get(`/v1/jobs/dbUpdate`); expect(response.status).to.equal(400); expect(response.body) .to.be.an("object") @@ -160,8 +160,7 @@ describe("API Tests", () => { describe("GET /v1/jobs/:job - Job name error", () => { it("should respond with code 400 and Job name error", async () => { - const response = await request(app).get(`/v1/jobs/dbupdate`).set({ "x-api-key": process.env.API_KEY}); - console.log(response.body) + const response = await request(app).get(`/v1/jobs/unknownJob`).set({ "x-api-key": process.env.API_KEY}); expect(response.status).to.equal(400); expect(response.body) .to.be.an("object") @@ -172,16 +171,15 @@ describe("API Tests", () => { describe("GET /v1/jobs/:job", () => { it("should respond with json and a job configuration for the specified job", async () => { - const response = await request(app).get(`/v1/jobs/dbUpdateJob`).set({ "x-api-key": process.env.API_KEY}); + const response = await request(app).get(`/v1/jobs/dbUpdate`).set({ "x-api-key": process.env.API_KEY}); expect(response.status).to.equal(200); - console.log(response.body); }); }); describe("PATCH /v1/jobs/:job - API KEY error", () => { it("should respond with code 400 and Header error", async () => { - const response = await request(app).patch(`/v1/jobs/dbUpdateJob`); + const response = await request(app).patch(`/v1/jobs/dbUpdate`); expect(response.status).to.equal(400); expect(response.body) .to.be.an("object") @@ -198,7 +196,7 @@ describe("API Tests", () => { }; const response = await request(app) - .patch(`/v1/jobs/dbUpdate`) + .patch(`/v1/jobs/unknownJob`) .send(payload) .set({ "x-api-key": process.env.API_KEY, @@ -219,7 +217,7 @@ describe("API Tests", () => { }; const response = await request(app) - .patch(`/v1/jobs/dbUpdateJob`) + .patch(`/v1/jobs/dbUpdate`) .send(payload) .set({ "x-api-key": process.env.API_KEY, @@ -240,7 +238,7 @@ describe("API Tests", () => { }; const response = await request(app) - .patch(`/v1/jobs/dbUpdateJob`) + .patch(`/v1/jobs/dbUpdate`) .send(payload) .set({ "x-api-key": process.env.API_KEY,