CI Test for get all interface lifecycle types
[sdc.git] / openecomp-bdd / stepDefinitions / Collaboration_Steps.js
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 const {Then, When, Given} = require('cucumber');
17 const assert = require('assert');
18 const util = require('./Utils.js');
19
20 /**
21  * @module Collaboration
22  * @description Adds the user with the given user ID as a contributor on the item
23  * @exampleFile Example_Collaboration.feature
24  * @step I want to add user {string} as a contributor to this Item
25  **/
26 When('I want to add user {string} as a contributor to this Item', function(string)  {
27         let path = '/items/' + this.context.item.id + '/permissions/Contributor';
28         let inputData = {removedUsersIds:[],addedUsersIds:[string]};
29         return util.request(this.context, 'PUT', path, inputData);
30 });
31
32 /**
33  * @module Collaboration
34  * @description Adds the user with the given user ID as a contributor on the item
35  * @exampleFile Example_Collaboration.feature
36  * @step I want to remove user {string} as a contributor to this Item
37  **/
38 When('I want to remove user {string} as a contributor to this Item', function(string)  {
39         let path = '/items/' + this.context.item.id + '/permissions/Contributor';
40         let inputData = {removedUsersIds:[string],addedUsersIds:[]};
41         return util.request(this.context, 'PUT', path, inputData);
42 });
43
44 /**
45  * @module Collaboration
46  * @description Changes the owner to the given User ID
47  * @exampleFile Example_Collaboration.feature
48  * @step I want to change the owner to user {string} on this Item
49  **/
50 When('I want to change the owner to user {string} on this Item', function(string)  {
51         let path = '/items/' + this.context.item.id + '/permissions/Owner';
52         let inputData = {removedUsersIds:[],addedUsersIds:[string]};
53         return util.request(this.context, 'PUT', path, inputData);
54 });
55
56
57 /**
58  * @module Collaboration
59  * @description Checks the role for a user on the item by User id and Role can be either: Contributor/Owner
60  * @exampleFile Example_Collaboration.feature
61  * @step I want check user {string} has role {string} on this Item
62  **/
63 When('I want to check user {string} has role {string} on this Item', function(string, string2)  {
64         let path = '/items/' + this.context.item.id + '/permissions';
65         return util.request(this.context, 'GET', path).then(results => {
66                 for (i in results.data.results) {
67                         if (results.data.results[i].userId === string) {
68                                 assert.equal(string2.toLowerCase(), results.data.results[i].permission.toLowerCase());
69                                 return;
70                         }
71                 }
72                 assert.fail('User not found');
73         });
74 });
75
76 /**
77  * @module Collaboration
78  * @description Checks the user wth this Id has no permissions on this item
79  * @exampleFile Example_Collaboration.feature
80  * @step I want check user {string} has rno permissions on this Item
81  **/
82 When('I want to check user {string} has no permissions on this Item', function(string)  {
83         let path = '/items/' + this.context.item.id + '/permissions';
84         return util.request(this.context, 'GET', path).then(results => {
85                 for (i in results.data.results) {
86                         if (results.data.results[i].userId === string) {
87                                 assert.fail('Found', null, 'User should not have permissions');
88                                 return;
89                         }
90                 }
91         });
92 });
93
94 /**
95  * @module Collaboration
96  * @description Gets the permissions for the Item
97  * @exampleFile Example_Collaboration.feature
98  * @step I want to get the permissions for this Item
99  **/
100 When('I want to get the permissions for this Item', function()  {
101         let path = '/items/' + this.context.item.id + '/permissions';
102         return util.request(this.context, 'GET', path);
103 });
104
105 /**
106  * @module Collaboration
107  * @description Changes the user for the Rest calls
108  * @exampleFile Example_Collaboration.feature
109  * @step I want to set the user to {string}
110  **/
111 When('I want to set the user to {string}', function(string)  {
112         this.context.headers['onboarding'].USER_ID = string;
113 });