Skip to content

Commit 3876c1c

Browse files
author
Serhat Bolsu
committed
README added to explain test suites
1 parent 50d266a commit 3876c1c

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,32 @@ run the server with
1616

1717
```npm start```
1818

19+
### Examples
20+
These are example usages of library. From 1 to 3 abstraction of endpoints increases.
21+
22+
#### 1- basic.spec.js
23+
Directly using superagent to make http requests.
24+
There are no helpers. Verification done with jest expect.
25+
26+
#### 2- basic_resource.spec.js
27+
Uses a BaseAPi.js object as a wrapper around superagent.
28+
29+
**Benefit:**
30+
31+
- Wrap around common request parameters
32+
- Can implement authentication at this level.
33+
- BaseURL is directly parsed from config
34+
- Can implement retry
35+
- superagent chain pattern can still be used
36+
37+
#### 3-base_api_resource.spec.js
38+
39+
- Used resource object, this is a similar method used in selenium with **page Objects**
40+
- Vegetable(endpoint resource) is converted to an object upon retrieval
41+
- in `vegetable.resource.js` you can write various methods with regards to this specific endpoint.
42+
- re-usability increased with common vegetable endpoint functions.
43+
- usage of superagent/requests encapsulated, however still usable look at tc#3
44+
45+
### ToDO
46+
- Allure reporting
47+
- Jenkinsfile

resources/vegetable.resource.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class VegetableResource extends BaseApi {
1212
constructor() {
1313
super();
1414
this.path = '/vegetables';
15+
this.vegetables = [];
1516
}
1617

1718
async create(name, price, releaseDate, origin) {
@@ -27,7 +28,12 @@ class VegetableResource extends BaseApi {
2728

2829
async getAll(optional=true) {
2930
const res = await this.get(this.path, {}, { optional: optional });
30-
return res.body.map((vegy)=> new Vegetable(vegy));
31+
this.vegetables = res.body.map((vegy)=> new Vegetable(vegy));
32+
return this.vegetables;
33+
}
34+
35+
getUniqueVegetables() {
36+
return new Set(this.vegetables.map((veg)=>veg.name));
3137
}
3238
}
3339

test/basic.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Vegetables baseline without framework', function() {
1616
};
1717
const res = await request.post(baseUrl + '/vegetables')
1818
.send(vegetable);
19-
expect(res.status).toBe(201);
19+
expect(res.ok).toBeTruthy();
2020
expect(res.text).toMatch(/added: Orange/);
2121
});
2222

test/basic_api_resource.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ describe('Vegetables - using Api Resource facade', function() {
44
it('should get default', async function() {
55
const vegetables = await api.vegetable().getAll();
66
expect(vegetables[0]).toHaveProperty('id');
7+
console.log(api.vegetable().getUniqueVegetables());
78
});
89

910
it('should get without optional', async function() {

0 commit comments

Comments
 (0)