Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2a7396e
post and get methods
Daniela-git Aug 19, 2021
4f038f4
patch and delete request
Daniela-git Aug 19, 2021
d89ec27
travis setup
Daniela-git Aug 19, 2021
7ff2836
mochawesome
Daniela-git Aug 19, 2021
aeefee6
mochawesome setup
Daniela-git Aug 19, 2021
9cd5b6c
config github auth
Daniela-git Aug 19, 2021
3962a99
using get method
Daniela-git Aug 20, 2021
98013a0
created GithubRequest.js
Daniela-git Aug 20, 2021
7baea28
move the data to a file
Daniela-git Aug 20, 2021
f25cf05
finish the get tests
Daniela-git Aug 20, 2021
b211f62
add mocha option in package.json
Daniela-git Aug 20, 2021
2991281
Download error (#1)
Daniela-git Aug 20, 2021
0441bc8
trying the put method
Daniela-git Aug 20, 2021
dcb2d9e
trying to fix the error
Daniela-git Aug 20, 2021
97e8a85
add travis secret
Daniela-git Aug 20, 2021
b61e5d4
remove the exeptions from the package.json and add key in travis
Daniela-git Aug 20, 2021
06434c7
change in download repo test
Daniela-git Aug 20, 2021
357e6e4
change in download repo test
Daniela-git Aug 20, 2021
9f9af45
finished put method
Daniela-git Aug 20, 2021
710d09d
finished post/patch methos
Daniela-git Aug 20, 2021
9d917b7
added delete method
Daniela-git Aug 20, 2021
a4501bc
little fixes
Daniela-git Aug 20, 2021
b158df1
Merge branch 'putmethod' into dev
Daniela-git Aug 20, 2021
10e4fe6
Merge branch 'main' into dev
Daniela-git Aug 20, 2021
96d3d87
create gist
Daniela-git Aug 20, 2021
736e35e
finished delete method
Daniela-git Aug 23, 2021
14ce439
finishe head method
Daniela-git Aug 23, 2021
39ede07
time and query parameters
Daniela-git Aug 23, 2021
ca4993e
Merge branch 'reponse_times' into dev
Daniela-git Sep 13, 2021
a358977
all the tests
Daniela-git Sep 13, 2021
db5311e
Merge branch 'dev' of https://github.com/Daniela-git/workshop-api-tes…
Daniela-git Sep 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ notifications:
email: false
branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"
env:
global:
- secure: esvvZQjX1uwAUBdDao5V8dzMFah9NEL3uSb9fbiKcQunegTBZEU3RoAuHywYshghskZ4MXKhe+6vyjAJvVrV5pcD2bdEHQCOEySfoDs+doLwKjH9bPZOefQ7WMOZF9xHAJ/OzhFyQECwH2Z9t3pHAvApraGszUyzSSU+OS0FQKqvdvG65E0mMTc1E60l6lbH12hHs8+cSrM6BUuiesUD8wwWFMABSZFTdkQV7QPlRKy7fSban/PelBDpvqnEQj1j8qCwTnQyakGl0J6BhmlaCtEjaRcSWK80D8CmhoPaFIjz7gR9gxFOpPaVq5jjWtjIIN++N4gsnpQNASt0l9WZTJHl2QOvCdOh2KDa0WSWj81Ic7S0+70+Qfawi4M2wMjiH+pS10dQj9KE/FZoHUGLu4HWvviLkLKX5DfCrQm+ehQPGP/HWslXlFpKrbFGOshn6xhUFZBa+jp1kcZjYDpCACVnNa6GJfr5hF4JlD9/00yafaGovtV56BjSHuj5Zn4KJidZD8xIP7Wg+Vlvhvf08UB+HiBEX+lMJaZRAcFZMg3rPNe9UfdHffk+i7LCWKUdFW4lbd8vn3yj2zzlsfKaOihIS+R+kvuWOX1nHndmC94GF1ZWo28DY55Dqud8AdtAwYn+iQNOfkgA2RSbi8gtarTC5Ehx6GbBKkp2tavVXIc=
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"http-status-codes": "^2.1.4",
"md5": "^2.3.0",
"mocha": "^9.0.3",
"mochawesome": "^6.2.2"
"mochawesome": "^6.2.2",
"superagent-response-time": "^1.0.3"
},
"dependencies": {
"superagent": "^6.1.0",
Expand Down
38 changes: 38 additions & 0 deletions src/GithubRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,44 @@ class GithubRequest {
.set('User-Agent', 'agent');
return response;
}

async authPut(url) {
const response = await agent
.put(url)
.auth('token', process.env.ACCESS_TOKEN)
.set('User-Agent', 'agent');
return response;
}
async authPost(url, query) {
const response = await agent
.post(url)
.auth('token', process.env.ACCESS_TOKEN)
.set('User-Agent', 'agent')
.send(query);
return response;
}
async authPatch(url, query) {
const response = await agent
.patch(url)
.auth('token', process.env.ACCESS_TOKEN)
.set('User-Agent', 'agent')
.send(query);
return response;
}
async authDelete(url) {
const response = await agent
.delete(url)
.auth('token', process.env.ACCESS_TOKEN)
.set('User-Agent', 'agent');
return response;
}
async authHead(url) {
const response = await agent
.head(url)
.auth('token', process.env.ACCESS_TOKEN)
.set('User-Agent', 'agent');
return response;
}
}

module.exports = new GithubRequest();
19 changes: 19 additions & 0 deletions src/data/DeleteMethod.data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
deleteData = {
query: {
description: 'gist to try delete method',
public: true,
files: {
'promise.js': {
content: `const aplicarDescuento = new Promise(function (resolve, reject) {
const descuento = false;
if (descuento) {
resolve("descuento aplicado");
} else {
reject("no se puede aplicar");
}});`,
},
},
},
};

module.exports = deleteData;
8 changes: 7 additions & 1 deletion src/data/GetMethod.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ getData = {
path: 'README.md',
sha: '1eb7c4c6f8746fcb3d8767eca780d4f6c393c484',
},
md5Value: 'c95c49b42787e38e0d02793d605395f1',
md5Value: 'a6519e2b84135654bb3ec9b47f114247',
md5RawFile: '3449c9e5e332f1dbb81505cd739fbf3f',
};

postData = {
issueInfo: {
title: 'trying github api',
body: null,
},
};
module.exports = getData;
12 changes: 12 additions & 0 deletions src/data/postMethod.data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
postData = {
issueInfo: {
title: 'trying github api',
body: null,
},
issueModifyInfo: {
title: 'trying github api',
body: 'check my body',
},
};

module.exports = postData;
57 changes: 57 additions & 0 deletions test/Github.Put.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const statusCode = require('http-status-codes');
const { expect } = require('chai');
const githubReq = require('../src/GithubRequest.js');

const urlBase = 'https://api.github.com';
const githubUserName = 'aperdomob';

describe('Trying the Github api put method', () => {
let follow;
beforeEach(async () => {
follow = await githubReq.authPut(
`${urlBase}/user/following/${githubUserName}`
);
});
it('response after the follow', () => {
expect(follow.status).to.equal(statusCode.NO_CONTENT);
expect(follow.body).to.be.empty;
});
describe('Check if following a user worked', () => {
let allFollowing;
beforeEach(async () => {
const response = await githubReq.authGet(`${urlBase}/user/following`);
allFollowing = response.body.find(
(user) => user.login === githubUserName
);
});
it('shoul be following the user', () => {
expect(allFollowing.login).to.eq(githubUserName);
});
});

describe('Trying to follow the same user again', () => {
let followAgain;
beforeEach(async () => {
followAgain = await githubReq.authPut(
`${urlBase}/user/following/${githubUserName}`
);
});
it('response after the follow again', () => {
expect(followAgain.status).to.equal(statusCode.NO_CONTENT);
expect(followAgain.body).to.be.empty;
});

describe('Check if following a user again worked', () => {
let allFollowing;
beforeEach(async () => {
const response = await githubReq.authGet(`${urlBase}/user/following`);
allFollowing = response.body.find(
(user) => user.login === githubUserName
);
});
it('shoul be following the user', () => {
expect(allFollowing.login).to.eq(githubUserName);
});
});
});
});
31 changes: 31 additions & 0 deletions test/Github.Redirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const expect = require('chai').expect;
const statuscode = require('http-status-codes');
const githubReq = require('../src/GithubRequest.js');

const urlBase = 'https://github.com';
const newUrl = `${urlBase}/aperdomob/new-redirect-test`;
const url = `${urlBase}/aperdomob/redirect-test`;
describe('Trying head method', () => {
let resHead;
beforeEach(async () => {
try {
await githubReq.authHead(url);
} catch (error) {
resHead = error;
}
});
it('checking the redirect exist', () => {
expect(resHead.status).to.eq(statuscode.MOVED_PERMANENTLY);
expect(resHead.response.header.location).to.equal(newUrl);
});

describe('checking the redirect works', () => {
let resRedirect;
beforeEach(async () => {
resRedirect = await githubReq.authGet(url);
});
it('the url must be the new url', () => {
expect(resRedirect.status).to.eq(statuscode.OK);
});
});
});
8 changes: 5 additions & 3 deletions test/GithubApi.Authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ const repository = 'workshop-api-testing-js';
describe('Github Api Test', () => {
describe('Authentication', () => {
it('Via OAuth2 Tokens by Header', async () => {
const response = await agent.get(`${urlBase}/repos/${githubUserName}/${repository}`)
const response = await agent
.get(`${urlBase}/repos/${githubUserName}/${repository}`)
.auth('token', process.env.ACCESS_TOKEN)
.set('User-Agent', 'agent');

expect(response.status).to.equal(statusCode.OK);
expect(response.body.description).equal('This is a Workshop about Api Testing in JavaScript');
expect(response.body.description).equal(
'This is a Workshop about Api Testing in JavaScript'
);
});

it('Via OAuth2 Tokens by parameter', async () => {
Expand All @@ -31,4 +34,3 @@ describe('Github Api Test', () => {
});
});
});

59 changes: 59 additions & 0 deletions test/GithubApi.Gist.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const chai = require('chai');
const expect = require('chai').expect;
const chaiSubset = require('chai-subset');
const statuscode = require('http-status-codes');
const githubReq = require('../src/GithubRequest.js');
const data = require('../src/data/deleteMethod.data');

chai.use(chaiSubset);

const urlBase = 'https://api.github.com';
describe('Trying delete method', () => {
let gist;
let gistRes;
beforeEach(async () => {
const url = `${urlBase}/gists`;
gistRes = await githubReq.authPost(url, data.query);
gist = gistRes.body;
});
it('the gist should be created', () => {
expect(gistRes.status).to.eq(statuscode.CREATED);
expect(gist).containSubset(data.query);
});

describe('checking if the gist exist', () => {
let gistInfo;
beforeEach(async () => {
res = await githubReq.authGet(gist.url);
gistInfo = res.body;
});
it('the gist should exist', () => {
expect(gistInfo.id).to.eq(gist.id);
expect(gistInfo).to.exist;
});
});

describe('delete the gist', () => {
let resDelete;
beforeEach(async () => {
resDelete = await githubReq.authDelete(gist.url);
});
it('the gist should be deleted', () => {
expect(resDelete.status).to.eq(statuscode.NO_CONTENT);
});

describe('checking if the gist was delete', () => {
let resCheckDelete;
beforeEach(async () => {
try {
await githubReq.authGet(gist.url);
} catch (error) {
resCheckDelete = error.status;
}
});
it('the gist should exist', () => {
expect(resCheckDelete).to.eq(statuscode.NOT_FOUND);
});
});
});
});
56 changes: 56 additions & 0 deletions test/GithubApi.Issu.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const chai = require('chai');
const expect = require('chai').expect;
const chaiSubset = require('chai-subset');
const githubReq = require('../src/GithubRequest.js');
const data = require('../src/data/postMethod.data');

chai.use(chaiSubset);

const urlBase = 'https://api.github.com';
describe('Trying post/patch methods', () => {
let loginUser;
beforeEach(async () => {
const res = await githubReq.authGet(`${urlBase}/user`);
loginUser = res.body;
});
it('should have at least one public repo', () => {
expect(loginUser.public_repos).to.be.greaterThan(0);
});

describe('getting all repositories', () => {
let repo;
beforeEach(async () => {
const repos = await githubReq.authGet(`${loginUser.repos_url}`);
repo = repos.body[0];
});
it('then the repo should exist', () => {
expect(repo).to.exist;
});
describe('Create an issue', () => {
let issue;
beforeEach(async () => {
const url = `${urlBase}/repos/${loginUser.login}/${repo.name}/issues`;
const res = await githubReq.authPost(url, {
title: 'trying github api',
});
issue = res.body;
});
it('the issue should be created', () => {
expect(issue).containSubset(data.issueInfo);
});
describe('Modify an issue', () => {
let issueModify;
beforeEach(async () => {
const url = `${urlBase}/repos/${loginUser.login}/${repo.name}/issues/${issue.number}`;
const res = await githubReq.authPatch(url, {
body: 'check my body',
});
issueModify = res.body;
});
it('the issue should be modified', () => {
expect(issueModify).containSubset(data.issueModifyInfo);
});
});
});
});
});
Loading