add user api feature file updated
This commit is contained in:
parent
a248921d73
commit
f7dab981c7
@ -65,3 +65,14 @@ Feature: Add user
|
|||||||
| g!!@%ui | नेपाली |
|
| g!!@%ui | नेपाली |
|
||||||
| swikriti@h | सिमप्ले $%#?&@name.txt |
|
| 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
|
||||||
|
|||||||
@ -2,6 +2,7 @@ const {Given, When, Then} = require('cucumber');
|
|||||||
const {client} = require('nightwatch-api');
|
const {client} = require('nightwatch-api');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const {getDolApiKey} = require('../setup');
|
||||||
let Login = {};
|
let Login = {};
|
||||||
|
|
||||||
Given('the administrator has browsed to the new users page', function () {
|
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);
|
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 header = {};
|
||||||
const url = client.globals.backend_url + 'api/index.php/users';
|
const url = client.globals.backend_url + 'api/index.php/users';
|
||||||
header['Accept'] = 'application/json';
|
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';
|
header['Content-Type'] = 'application/json';
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: 'POST',
|
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 adminHasCreatedUser = async function (dataTable) {
|
||||||
const userDetails = dataTable.hashes();
|
const userDetails = dataTable.hashes();
|
||||||
for (const user of userDetails) {
|
for (const user of userDetails) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user