From 042e84dc3e64d53aff5d189a248bbf42a49342f8 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Mon, 7 Aug 2023 14:33:20 +0200 Subject: [PATCH] fix: some improvements --- .github/workflows/npm-publish.yml | 23 +++++++++++++++++++++++ package.json | 8 ++++++++ src/GET_test.ts | 8 ++++---- stepObjects/custom.steps.ts | 5 ++++- stepObjects/userSteps.ts | 11 +++++++++++ 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/npm-publish.yml create mode 100644 stepObjects/userSteps.ts diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..2a2df44 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,23 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages + +name: Node.js Package + +on: + push: + branches: + - master + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 18 + registry-url: https://registry.npmjs.org/ + - run: npx semantic-release + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} + GH_TOKEN: ${{ secrets.GH_TOKEN }} \ No newline at end of file diff --git a/package.json b/package.json index 5aef42b..a8726e1 100644 --- a/package.json +++ b/package.json @@ -32,5 +32,13 @@ "allure-patch": "^1.0.3", "codeceptjs-expect": "^1.0.0", "form-data": "^3.0.0" + }, + "files": [ + "stepObjects/*", + "README.md" + ], + "repository": { + "type": "git", + "url": "https://github.com/kobenguyent/codeceptjs-rest-demo.git" } } diff --git a/src/GET_test.ts b/src/GET_test.ts index 4251f84..55ab7bf 100644 --- a/src/GET_test.ts +++ b/src/GET_test.ts @@ -3,22 +3,22 @@ const { I } = inject(); Feature('GET tests'); Scenario('Verify a successful call', async () => { - await I.sendGetRequest('/api/users?page=2'); + await I.getUserPerPage(2); I.seeResponseCodeIsSuccessful(); I.seeResponseContainsJson({page:2,per_page:6}) }); Scenario('Verify a not found call', async () => { - I.sendGetRequest('/api/users/266'); + await I.getUserById(266); I.seeResponseCodeIsClientError(); }); Scenario('Verify getting a single user', async () => { - const res = await I.sendGetRequest('/api/users/2'); + const res = await I.getUserById(2); await I.expectEqual(res.data.data.id, 2); }); Scenario('Verify getting list of users', async () => { - const res = await I.sendGetRequest('/api/users?page=2'); + const res = await I.getUserPerPage(2); await I.expectEqual(res.data.data[0].id, 7); }); diff --git a/stepObjects/custom.steps.ts b/stepObjects/custom.steps.ts index d6eafed..eba534c 100644 --- a/stepObjects/custom.steps.ts +++ b/stepObjects/custom.steps.ts @@ -1,3 +1,5 @@ +import userSteps from './userSteps'; + const faker = require('faker'); const FormData = require('form-data'); @@ -15,6 +17,7 @@ export = () => { let form = new FormData(); form.append(key, value); return form; - } + }, + ...userSteps }); } diff --git a/stepObjects/userSteps.ts b/stepObjects/userSteps.ts new file mode 100644 index 0000000..bf1f510 --- /dev/null +++ b/stepObjects/userSteps.ts @@ -0,0 +1,11 @@ +const userSteps = { + async getUserPerPage(page = 2) { + return this.sendGetRequest(`/api/users?page=${page}`); + }, + + async getUserById(id: number) { + return this.sendGetRequest(`/api/users/${id}`); + } +} + +export default userSteps; \ No newline at end of file