From f7dab981c799e3313feebcc0a2f6c4b98468989b Mon Sep 17 00:00:00 2001 From: SwikritiT Date: Wed, 21 Oct 2020 13:22:02 +0545 Subject: [PATCH] add user api feature file updated --- .../features/Api/apiAddUsers.feature | 13 ++++++++++- .../stepDefinitions/addUsersContext.js | 22 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/test/acceptance/features/Api/apiAddUsers.feature b/test/acceptance/features/Api/apiAddUsers.feature index 37d15e019db..77bb811d224 100644 --- a/test/acceptance/features/Api/apiAddUsers.feature +++ b/test/acceptance/features/Api/apiAddUsers.feature @@ -64,4 +64,15 @@ Feature: Add user | swi@ | s$5^2 | | g!!@%ui | नेपाली | | swikriti@h | सिमप्ले $%#?&@name.txt | - | !@#$%^&*()-_+ | España§àôœ€ | \ No newline at end of file + | !@#$%^&*()-_+ | España§àôœ€ | + + Scenario: Non-admin user with api key adds user + Given the admin has created the following users + | login | last name | password | api_key | + | Harry | Potter | hello123 | harrypotter | + When the non-admin user "Harry" with password "hello123" creates user with following details using API + | last name | Potter | + | login | Ginny | + | password | password | + Then the response status code should be "200" + And user with login "Ginny" should exist diff --git a/test/acceptance/stepDefinitions/addUsersContext.js b/test/acceptance/stepDefinitions/addUsersContext.js index 52dbee94470..19b57403b48 100644 --- a/test/acceptance/stepDefinitions/addUsersContext.js +++ b/test/acceptance/stepDefinitions/addUsersContext.js @@ -2,6 +2,7 @@ const {Given, When, Then} = require('cucumber'); const {client} = require('nightwatch-api'); const fetch = require('node-fetch'); const assert = require('assert'); +const {getDolApiKey} = require('../setup'); let Login = {}; Given('the administrator has browsed to the new users page', function () { @@ -56,11 +57,20 @@ Then('the response message should be {string}', function (expectedResponseMessag return getResponseMessage(expectedResponseMessage); }); -const createUserRequest = function (login, lastname, password, api_key = null) { +When('the non-admin user {string} with password {string} creates user with following details using API', async function (login, password, dataTable) { + const userDolApikey = await getDolApiKey(login, password); + return userCreatesUserWithApi(dataTable, userDolApikey); +}); + +const createUserRequest = function (login, lastname, password, api_key = null, dolApiKey = null) { const header = {}; const url = client.globals.backend_url + 'api/index.php/users'; header['Accept'] = 'application/json'; - header['DOLAPIKEY'] = client.globals.dolApiKey; + if (dolApiKey === null) { + header['DOLAPIKEY'] = client.globals.dolApiKey; + } else { + header['DOLAPIKEY'] = dolApiKey; + } header['Content-Type'] = 'application/json'; return fetch(url, { method: 'POST', @@ -84,6 +94,14 @@ const adminCreatesUserWithAPI = function (dataTable) { }); }; +const userCreatesUserWithApi = function (dataTable, dolApiKey) { + const userDetails = dataTable.rowsHash(); + return createUserRequest(userDetails['login'], userDetails['last name'], userDetails['password'], null, dolApiKey) + .then((res) => { + client.globals.response = res; + }); +}; + const adminHasCreatedUser = async function (dataTable) { const userDetails = dataTable.hashes(); for (const user of userDetails) {