Skip to content

Commit

Permalink
feat: added delete example; added github and gitlab support
Browse files Browse the repository at this point in the history
  • Loading branch information
jesantos committed Feb 26, 2024
1 parent 9e282f0 commit fc397fb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/api_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: API Testing Workflow
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
11 changes: 11 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
stages:
- test

api_test:
stage: test
image: node:14
script:
- npm install
- npm test
only:
- main
12 changes: 12 additions & 0 deletions test_server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ app.get('/posts/:id', async (req, res) => {
}
});

app.delete('/posts/:id', async (req, res) => {
const postId = parseInt(req.params.id);
const postIndex = posts.findIndex(p => p.id === postId);
if (postIndex > -1) {
posts.splice(postIndex, 1); // Remove the post from the array
await sleepRandom();
res.send('Post deleted successfully.');
} else {
res.status(404).send('Not Found');
}
});

app.get('/posts', async (req, res) => {
await sleepRandom()
res.json(posts);
Expand Down
11 changes: 11 additions & 0 deletions tests/test-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ testAuthenticationAndPostLifecycle:
- type: "equal"
target: "data.0.title"
expected: "My Updated Post"

- name: "Delete Post"
url: "http://localhost:3000/posts/{context.postId}"
method: "DELETE"
headers:
Authorization: "Bearer {context.authToken}"
assertions:
- type: "equal"
target: "status"
expected: 200

0 comments on commit fc397fb

Please sign in to comment.