-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
chore(package): merge ci changes from master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- your
tests
folder is insidesrc
, it should be outside.
src/tests/unit/helper/nock-apiv6.ts
Outdated
export const createChangesetNock = (): void => { | ||
nock(`${host}:${port}`) | ||
.put(`${createChangesetEndPoint}`) | ||
.reply(200, '12'); | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/tests/unit/helper/nock-apiv6.ts
Outdated
|
||
export const createChangesetNock = (): void => { | ||
nock(`${host}:${port}`) | ||
.put(`${createChangesetEndPoint}`) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
.eslintrc.js
Outdated
"@typescript-eslint" | ||
], | ||
"rules": { | ||
semi: [2, "always"] | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you didn't use our eslint-config
https://github.com/MapColonies/eslint-config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
index.ts
Outdated
import Apiv6 from './src/api/v6'; | ||
|
||
export default Apiv6; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/api/v6/index.ts
Outdated
} | ||
setUserName(username: string): boolean { | ||
this.username = username; | ||
return true; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind ...fixed
src/api/v6/index.ts
Outdated
setUserName(username: string): boolean { | ||
this.username = username; | ||
return true; | ||
} | ||
setPassword(password: string): boolean { | ||
this.password = password; | ||
return true; | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/api/v6/index.ts
Outdated
catch (e) { | ||
const { response: { status: code, data: message } } = e; | ||
return response(code, message); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/tests/unit/unit.test.ts
Outdated
@@ -0,0 +1,43 @@ | |||
import { expect } from 'chai'; | |||
import { describe, it } from 'mocha'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, done
src/tests/unit/unit.test.ts
Outdated
before(async function () { | ||
createChangesetNockNotAuth(); | ||
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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'", |
There was a problem hiding this comment.
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
tests/unit/unit.test.ts
Outdated
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); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
717d2a7
to
45e5e8f
Compare
45e5e8f
to
a78eca8
Compare
There was a problem hiding this 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
461f2af
to
e6ca108
Compare
1b1b7c9
to
6255647
Compare
6255647
to
350eaca
Compare
Closes #2