Skip to content

Commit

Permalink
test: run jest tests in CI (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored Nov 17, 2023
1 parent bb261cd commit 4e62da6
Show file tree
Hide file tree
Showing 7 changed files with 1,726 additions and 222 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/lint.yml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Lint and Test

on:
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
- name: Set up Node.js
uses: actions/setup-node@7c12f8017d5436eb855f1ed4399f037a36fbd9e8 # v2
with:
node-version: "20.x"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run lint
run: npm run lint

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
- name: Set up Node.js
uses: actions/setup-node@7c12f8017d5436eb855f1ed4399f037a36fbd9e8 # v2
with:
# TODO: update to 20 when the tests run on it reliably.
node-version: "18.x"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Init
run: npm run turbo init
- name: Test
run: npm test
6 changes: 3 additions & 3 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
},
"dependencies": {
"@strapi/plugin-documentation": "^4.11.5",
"@strapi/plugin-i18n": "4.15.4",
"@strapi/plugin-i18n": "4.15.0",
"@strapi/plugin-users-permissions": "4.15.4",
"@strapi/provider-email-nodemailer": "^4.12.4",
"@strapi/strapi": "~4.15.0",
"@strapi/strapi": "4.15.4",
"nanoid": "^3.3.6",
"pg": "^8.11.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^5.3.4",
"strapi-plugin-config-sync": "^1.1.2",
"styled-components": "^5.3.11"
"styled-components": "5.3.3"
},
"author": {
"name": "A Strapi developer"
Expand Down
25 changes: 23 additions & 2 deletions apps/backend/src/api/post/controllers/post.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
const { ValidationError } = require("@strapi/utils").errors;

/**
* post controller
Expand Down Expand Up @@ -57,7 +58,17 @@ module.exports = createCoreController("api::post.post", ({ strapi }) => {
}

// call the default core action with modified data
return await super.create(ctx);
try {
return await super.create(ctx);
} catch (err) {
// TODO: DRY out error handling.
const isValidationError = err instanceof ValidationError;
if (isValidationError) {
ctx.throw(400, err);
} else {
ctx.throw(err);
}
}
},
async update(ctx) {
if (!helpers.isEditor(ctx)) {
Expand All @@ -77,7 +88,17 @@ module.exports = createCoreController("api::post.post", ({ strapi }) => {
delete ctx.request.body.data.slug_id;

// call the default core action with modified data
return await super.update(ctx);
try {
return await super.update(ctx);
} catch (err) {
// TODO: DRY out error handling.
const isValidationError = err instanceof ValidationError;
if (isValidationError) {
ctx.throw(400, err);
} else {
ctx.throw(err);
}
}
},
async schedule(ctx) {
try {
Expand Down
8 changes: 7 additions & 1 deletion apps/backend/tests/custom-post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ const expectedPost = {
slug: "test-slug",
body: "<p>test body</p>",
excerpt: null,
locale: "en",
// TODO: should we have this?
// locale: "en",
published_at: "2023-08-30T00:00:00.000Z",
created_at: expect.any(String),
updated_at: expect.any(String),
codeinjection_head: null,
codeinjection_foot: null,
ghost_id: null,
scheduled_at: null,
slug_id: expect.stringMatching(/[a-z0-9]{8}/),
};

const expectedAuthor = {
Expand Down
Loading

0 comments on commit 4e62da6

Please sign in to comment.