Skip to content

Commit 1b3e1a5

Browse files
author
Ville Jyrkkä
authored
Merge pull request #3 from apinf/hotfix/adding-api
Hotfix/adding api
2 parents 003e03c + 7c2749e commit 1b3e1a5

File tree

3 files changed

+93
-57
lines changed

3 files changed

+93
-57
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
test/node_modules

test/addapibackend.js

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ test.describe('Add API Backend', function() {
1111
var driver;
1212
var newUser = {
1313
added: false,
14-
email: ""
14+
email: "",
15+
password: ""
1516
};
1617
test.before(function() {
1718
driver = CommonUtils.buildDriver();
@@ -20,9 +21,13 @@ test.describe('Add API Backend', function() {
2021
driver.quit();
2122
});
2223
test.afterEach(function() {
24+
//TODO: after adding a new api, must delete it too as a new user
2325
CommonUtils.dashBoardSignOut(driver);
2426
if (newUser.added) {
25-
CommonUtils.deleteNewUser(driver, newUser.email);
27+
var mainPage = CommonUtils.deleteNewUser(driver, newUser.email, newUser.password);
28+
mainPage.getText().then(function(text) {
29+
assert.equal('Latest APIs', text);
30+
});
2631
}
2732
});
2833
test.it('8.1 should add/publish api backend as a new user', function() {
@@ -32,76 +37,109 @@ test.describe('Add API Backend', function() {
3237
userName = faker.internet.userName();
3338
}
3439
var email = faker.internet.email();
40+
var password = faker.internet.password();
3541
newUser.added = true;
3642
newUser.email = email;
37-
CommonUtils.fillSignUpForm(driver, userName, email, faker.internet.password());
43+
newUser.password = password;
44+
CommonUtils.fillSignUpForm(driver, userName, email, password);
3845
CommonUtils.goToDashboard(driver);
3946
AddAPIBackendUtil.addNewBackend(driver, {
40-
backendName: 'NewBackend',
41-
description: 'Test Description',
42-
hostName: 'google.com',
43-
portNumber: '80',
44-
frontendPrefix: '/test',
45-
backendPrefix: '/test'
47+
apiName: 'NewBackend v2',
48+
apiDescription: 'Test Description',
49+
apiURL: 'http://google.com'
4650
});
47-
var publishedAPIHostElement = driver.findElement(By.xpath('//*[@class="page-title"]'));
51+
// Get API name in an api page
52+
var publishedAPIHostElement = driver.findElement(By.id('api-header'));
4853
publishedAPIHostElement.getText().then(function(text){
49-
assert.equal(text, 'NewBackend');
54+
assert.equal(text, 'NewBackend v2');
5055
});
5156
});
5257
test.it('8.2 should add/publish api backend as a registered user who doesn\'t own any api', function(){
5358
newUser.added = false;
5459
CommonUtils.signIn(driver);
55-
CommonUtils.fillSignInForm(driver, 'test@test.test', 'testuser');
60+
CommonUtils.fillSignInForm(driver, 'robot@test.com', 'robottest');
5661
CommonUtils.goToDashboard(driver);
5762
AddAPIBackendUtil.addNewBackend(driver, {
58-
backendName: 'NewBackend',
59-
description: 'Test Description',
60-
hostName: 'google.com',
61-
portNumber: '80',
62-
frontendPrefix: '/test',
63-
backendPrefix: '/test'
63+
apiName: 'NewBackend',
64+
apiDescription: 'Test Description',
65+
apiURL: 'http://google.com'
6466
});
65-
var publishedAPIHostElement = driver.findElement(By.xpath('//*[@class="page-title"]'));
67+
var publishedAPIHostElement = driver.findElement(By.id('api-header'));
6668
publishedAPIHostElement.getText().then(function(text){
6769
assert.equal(text, 'NewBackend');
6870
});
6971
});
70-
test.it('8.3 should not add/publish api backend with missing fields', function() {
72+
test.it('8.3.1 should not add/publish api backend with missing API name field', function() {
73+
newUser.added = false;
74+
CommonUtils.signIn(driver);
75+
CommonUtils.fillSignInForm(driver, 'robot@test.com', 'robottest');
76+
CommonUtils.goToDashboard(driver);
77+
var values = {
78+
apiDescription: 'Test Description',
79+
apiURL: 'http://google.com'
80+
};
81+
AddAPIBackendUtil.clickAddNewBackend(driver);
82+
AddAPIBackendUtil.fillApiDescription(driver, values);
83+
AddAPIBackendUtil.fillApiURL(driver, values);
84+
AddAPIBackendUtil.savingInformation(driver);
85+
// Get the API Name field in form
86+
var hostRequiredErrorElement = driver.findElement(By.xpath('//*[@id="addApiForm"]/fieldset/div[1]/span'));
87+
hostRequiredErrorElement.getText().then(function(text) {
88+
assert.equal(text, 'API Name is required');
89+
});
90+
});
91+
test.it('8.3.2 should not add/publish api backend with missing URL field', function() {
7192
newUser.added = false;
7293
CommonUtils.signIn(driver);
73-
CommonUtils.fillSignInForm(driver, 'test@test.test', 'testuser');
94+
CommonUtils.fillSignInForm(driver, 'robot@test.com', 'robottest');
7495
CommonUtils.goToDashboard(driver);
7596
var values = {
76-
backendName: 'NewBackend',
77-
description: 'Test Description',
78-
hostName: '',
79-
portNumber: '80',
97+
apiName: 'NewBackend',
98+
apiDescription: 'Test Description'
8099
};
81100
AddAPIBackendUtil.clickAddNewBackend(driver);
82-
AddAPIBackendUtil.fillBaseInformation(driver, values);
83-
AddAPIBackendUtil.fillBackendInformation(driver, values);
84-
var hostRequiredErrorElement = driver.findElement(By.xpath('//*[@id="backend-information-form"]/div[2]/span'));
101+
AddAPIBackendUtil.fillApiName(driver, values);
102+
AddAPIBackendUtil.fillApiDescription(driver, values);
103+
AddAPIBackendUtil.savingInformation(driver);
104+
// Get the URL field in form
105+
var hostRequiredErrorElement = driver.findElement(By.xpath('//*[@id="addApiForm"]/fieldset/div[3]/span'));
85106
hostRequiredErrorElement.getText().then(function(text) {
86-
assert.equal(text, 'Host is required');
107+
assert.equal(text, 'URL is required');
87108
});
88109
});
89110
test.it('8.4 should not add/publish api backend with invalid host name', function() {
90111
newUser.added = false;
91112
CommonUtils.signIn(driver);
92-
CommonUtils.fillSignInForm(driver, 'test@test.test', 'testuser');
113+
CommonUtils.fillSignInForm(driver, 'robot@test.com', 'robottest');
93114
CommonUtils.goToDashboard(driver);
94115
AddAPIBackendUtil.addNewBackend(driver, {
95-
backendName: 'NewBackend',
96-
description: 'Test Description',
97-
hostName: 'google',
98-
portNumber: '80',
99-
frontendPrefix: '/test',
100-
backendPrefix: '/test'
116+
apiName: 'NewBackend',
117+
apiDescription: 'Test Description',
118+
apiURL: 'google.com'
119+
});
120+
// Get the URL field in form
121+
var errorElement = driver.findElement(By.xpath('//*[@id="addApiForm"]/fieldset/div[3]/span'));
122+
errorElement.getText().then(function(text){
123+
assert.equal(text, 'URL must be a valid URL');
101124
});
102-
var errorElement = driver.findElement(By.xpath('//*[@class="s-alert-box-inner"]/p'));
125+
});
126+
test.it('8.5 should not add/publish api with no unique name', function() {
127+
newUser.added = false;
128+
CommonUtils.signIn(driver);
129+
CommonUtils.fillSignInForm(driver, 'robot@test.com', 'robottest');
130+
CommonUtils.goToDashboard(driver);
131+
var values = {
132+
apiName: 'NewBackend',
133+
apiDescription: 'Test Description',
134+
apiURL: 'http://google.com'
135+
};
136+
AddAPIBackendUtil.addNewBackend(driver, values);
137+
// Wait a moment for span is available
138+
driver.sleep(1000);
139+
// Get the API Name field in form
140+
var errorElement = driver.findElement(By.xpath('//*[@id="addApiForm"]/fieldset/div[1]/span'));
103141
errorElement.getText().then(function(text){
104-
assert.include(text, 'Could not resolve host: no address for google');
142+
assert.equal(text, 'API Name must be unique');
105143
});
106144
});
107145
});

test/addapibackendutil.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,30 @@ var By = require('selenium-webdriver').By;
33
var AddAPIBackend = {
44
addNewBackend: function(driver, values) {
55
this.clickAddNewBackend(driver);
6-
this.fillBaseInformation(driver, values);
7-
this.fillBackendInformation(driver, values);
8-
this.fillMatchingURLPrefixes(driver, values);
6+
this.fillApiName(driver, values);
7+
this.fillApiDescription(driver, values);
8+
this.fillApiURL(driver, values);
9+
this.savingInformation(driver);
910
},
1011

1112
clickAddNewBackend: function(driver) {
12-
driver.findElement(By.xpath('//*[text()="API Backends"]')).click().then(function() {
13-
driver.sleep(2000);
14-
});
15-
driver.findElement(By.xpath('//*[text()="Add API Backend"]')).click();
13+
driver.findElement(By.xpath('//*[text()="Add API"]')).click();
1614
},
1715

18-
fillBaseInformation: function(driver, values) {
19-
driver.findElement(By.xpath('//*[@id="base-information-form"]/div/input')).sendKeys(values.backendName);
20-
driver.findElement(By.xpath('//*[@id="base-information-form"]/nav/button')).click();
16+
fillApiName: function(driver, values) {
17+
driver.findElement(By.xpath('//*[@id="addApiForm"]/fieldset/div[1]/input')).sendKeys(values.apiName);
2118
},
2219

23-
fillBackendInformation: function(driver, values) {
24-
driver.findElement(By.xpath('//*[@id="backend-information-form"]/div[1]/select/option[3]')).click();
25-
driver.findElement(By.xpath('//*[@id="backend-information-form"]/div[2]/input')).sendKeys(values.hostName);
26-
driver.findElement(By.xpath('//*[@id="backend-information-form"]/div[3]/input')).sendKeys(values.portNumber);
27-
driver.findElement(By.xpath('//*[@id="backend-information-form"]/nav/button[2]')).click();
20+
fillApiDescription: function(driver, values) {
21+
driver.findElement(By.xpath('//*[@id="addApiForm"]/fieldset/div[2]/textarea')).sendKeys(values.apiDescription);
2822
},
2923

30-
fillMatchingURLPrefixes: function(driver, values) {
31-
driver.findElement(By.xpath('//*[@id="prefixes-information-form"]/div/div[2]/div[1]/input')).sendKeys(values.frontendPrefix);
32-
driver.findElement(By.xpath('//*[@id="prefixes-information-form"]/div/div[2]/div[2]/input')).sendKeys(values.backendPrefix);
33-
driver.findElement(By.xpath('//*[@id="prefixes-information-form"]/nav/button[2]')).click();
24+
fillApiURL: function(driver, values) {
25+
driver.findElement(By.xpath('//*[@id="addApiForm"]/fieldset/div[3]/input')).sendKeys(values.apiURL);
26+
},
27+
28+
savingInformation: function(driver) {
29+
driver.findElement(By.xpath('//*[@id="addApiForm"]/button')).click();
3430
}
3531
}
3632

0 commit comments

Comments
 (0)