Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement PUT /api/0.6/changeset/create #7

Merged
merged 13 commits into from
Nov 29, 2020
Merged

Conversation

galta95
Copy link
Contributor

@galta95 galta95 commented Nov 26, 2020

Closes #2

Copy link
Contributor

@syncush syncush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. your tests folder is inside src, it should be outside.

Comment on lines 13 to 17
export const createChangesetNock = (): void => {
nock(`${host}:${port}`)
.put(`${createChangesetEndPoint}`)
.reply(200, '12');
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function name does not indicate whether if the nock is for success or failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this and transfered to the test itself


export const createChangesetNock = (): void => {
nock(`${host}:${port}`)
.put(`${createChangesetEndPoint}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for a string template if you are using a string variable already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.eslintrc.js Outdated
Comment on lines 16 to 21
"@typescript-eslint"
],
"rules": {
semi: [2, "always"]
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

index.ts Outdated
Comment on lines 1 to 3
import Apiv6 from './src/api/v6';

export default Apiv6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you bundle the code, you should bundle the code under src folder -> this file should be under /src

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

package.json Outdated
"axios": "^0.21.0",
"typescript": "^4.1.2"
"typescript": "^4.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typescript should be a devDep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
setUserName(username: string): boolean {
this.username = username;
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to return true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind ...fixed

Comment on lines 46 to 53
setUserName(username: string): boolean {
this.username = username;
return true;
}
setPassword(password: string): boolean {
this.password = password;
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop the two function in favor of setCreds(username, password)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 68 to 71
catch (e) {
const { response: { status: code, data: message } } = e;
return response(code, message);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have talked about going over the responses of the API by their spec and create meaningful Exceptions like 400 bad request or 405 method not allowed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,43 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to import describe and it once you run mocha you get them as a global function, if it is because you had a listing problem you need to specify in eslintrc that you use mocha

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, done

Comment on lines 28 to 30
before(async function () {
createChangesetNockNotAuth();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you use an async function but does not use await inside, it is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@syncush
Copy link
Contributor

syncush commented Nov 26, 2020

Please add prettier to the project

package.json Outdated
@@ -4,7 +4,7 @@
"description": "easy communication with osm api",
"main": "index.js",
"scripts": {
"test": "mocha -r ts-node/register 'src/tests/unit/unit.test.ts'",
"test": "mocha -r ts-node/register 'tests/**/*.ts'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test file pattern should be tests/**/*.test.ts

Comment on lines 1 to 44
import { expect } from 'chai';
import nock = require('nock');

import Apiv6 from '../../src/index';
import { testConf } from './config/tests-config';
import { createChangesetEndPoint } from '../../src/lib/endpoints';

const { url, username, password } = testConf;

describe('apiv6', async function () {
const apiv6 = new Apiv6(url, username, password);
describe('happy flow', async function () {
describe('/changeset/create', async function () {
describe('with register user', async function () {
it('should return 200 and changset number', async function () {
nock(url).put(createChangesetEndPoint).reply(200, '12');
const res = await apiv6.createChangeset("test-generator", "test-user");

expect(res).to.be.a('object')
.with.property('code')
.and.to.be.equal(200);
expect(res).to.have.property('message')
.and.to.be.equal(12);
});
});
describe('with unregisterd user', async function () {
it('should return error', async function () {
nock(url).put(createChangesetEndPoint).reply(401, "Couldn't authenticate you");
apiv6.setCreds('not-registerd', '123456');

try {
await apiv6.createChangeset("test-generator", "test-user");
} catch (e) {
expect(e).to.be.a('Error')
.with.property('message')
.and.to.be.equal('Couldn\'t authenticate you');
expect(e).to.have.property('status')
.and.to.be.equal(401);
}
});
});
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file name should be apiv6.test.ts

package.json Outdated
@@ -29,9 +32,7 @@
"homepage": "https://github.com/MapColonies/node-osm-api#readme",
"dependencies": {
"@types/node": "^14.14.9",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types node should be devDep

@galta95 galta95 force-pushed the create-changeset-rout branch from 717d2a7 to 45e5e8f Compare November 29, 2020 13:12
@galta95 galta95 force-pushed the create-changeset-rout branch from 45e5e8f to a78eca8 Compare November 29, 2020 13:33
Copy link
Contributor

@syncush syncush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should run lint on test files

* ci(tests): added unit tets

* fix(github- workflows): split to two different .yml files for each job category
@galta95 galta95 force-pushed the create-changeset-rout branch 8 times, most recently from 461f2af to e6ca108 Compare November 29, 2020 14:35
@galta95 galta95 force-pushed the create-changeset-rout branch 4 times, most recently from 1b1b7c9 to 6255647 Compare November 29, 2020 14:50
@galta95 galta95 force-pushed the create-changeset-rout branch from 6255647 to 350eaca Compare November 29, 2020 14:55
@syncush syncush merged commit aef079b into apiv6 Nov 29, 2020
@galta95 galta95 deleted the create-changeset-rout branch December 3, 2020 14:48
syncush pushed a commit that referenced this pull request Dec 3, 2020
* feat(/api/0.6/changeset/create): create changeset (#7)

* feat(apiv6): implemented closeChangeset (#12)

* feat(apiv6): implemented upload Changeset (#14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants