add user api feature file updated

This commit is contained in:
SwikritiT 2020-10-21 13:22:02 +05:45
parent a248921d73
commit f7dab981c7
2 changed files with 32 additions and 3 deletions

View File

@ -64,4 +64,15 @@ Feature: Add user
| swi@ | s$5^2 |
| g!!@%ui | |
| swikriti@h | ि $%#?&@name.txt |
| !@#$%^&*()-_+ | España§àôœ€ |
| !@#$%^&*()-_+ | 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

View File

@ -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) {