This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
skill & skillsProvider removal #126
Open
Sande3p
wants to merge
5
commits into
topcoder-archive:feature/removing_skill_model
Choose a base branch
from
Sande3p:feature/removing_skill_model
base: feature/removing_skill_model
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,787
−1,265
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
AUTH0_URL: 'https://topcoder-dev.auth0.com/oauth/token', | ||
AUTH0_AUDIENCE: 'https://m2m.topcoder-dev.com/', | ||
TOKEN_CACHE_TIME: 6000, | ||
AUTH0_CLIENT_ID: 'client_id', | ||
AUTH0_CLIENT_SECRET: 'secret', | ||
AUTH0_PROXY_SERVER_URL: 'proxy_url' | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const { DataTypes } = require('sequelize') | ||
|
||
module.exports = { | ||
up: async (query) => { | ||
await query.removeConstraint('UsersSkills', 'UsersSkills_skillId_fkey') | ||
await query.removeConstraint('OrganizationSkillsProviders', 'OrganizationSkillsProviders_skillProviderId_fkey') | ||
await query.dropTable('Skills') | ||
await query.dropTable('SkillsProviders') | ||
}, | ||
down: async (query) => { | ||
await query.createTable('Skills', { | ||
id: { | ||
primaryKey: true, | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4 | ||
}, | ||
createdBy: { | ||
type: DataTypes.STRING | ||
}, | ||
updatedBy: { | ||
type: DataTypes.STRING | ||
}, | ||
name: { | ||
type: DataTypes.STRING | ||
}, | ||
externalId: { | ||
type: DataTypes.STRING | ||
}, | ||
uri: { | ||
type: DataTypes.STRING | ||
}, | ||
created: { | ||
type: DataTypes.DATE, | ||
allowNull: false | ||
}, | ||
updated: { | ||
type: DataTypes.DATE | ||
} | ||
}) | ||
await query.createTable('SkillsProviders', { | ||
id: { | ||
primaryKey: true, | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4 | ||
}, | ||
createdBy: { | ||
type: DataTypes.STRING | ||
}, | ||
updatedBy: { | ||
type: DataTypes.STRING | ||
}, | ||
name: { | ||
type: DataTypes.STRING | ||
}, | ||
created: { | ||
type: DataTypes.DATE, | ||
allowNull: false | ||
}, | ||
updated: { | ||
type: DataTypes.DATE | ||
} | ||
}) | ||
await query.addColumn('Skills', 'skillProviderId', { | ||
type: DataTypes.UUID, | ||
references: { | ||
model: 'SkillsProviders', | ||
key: 'id' | ||
}, | ||
onUpdate: 'CASCADE' | ||
}) | ||
await query.addConstraint('OrganizationSkillsProviders', { | ||
fields: ['skillProviderId'], | ||
type: 'foreign key', | ||
name: 'OrganizationSkillsProviders_skillProviderId_fkey', | ||
references: { | ||
table: 'SkillsProviders', | ||
field: 'id' | ||
}, | ||
onUpdate: 'CASCADE' | ||
}) | ||
await query.addConstraint('UsersSkills', { | ||
fields: ['skillId'], | ||
type: 'foreign key', | ||
name: 'UsersSkills_skillId_fkey', | ||
references: { | ||
table: 'Skills', | ||
field: 'id' | ||
}, | ||
onUpdate: 'CASCADE' | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* | ||
* Prepare for tests. | ||
*/ | ||
process.env.NODE_ENV = 'test' | ||
require('../src/bootstrap') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
const _ = require('lodash') | ||
const config = require('config') | ||
const chai = require('chai') | ||
const chaiHttp = require('chai-http') | ||
const chaiAsPromised = require('chai-as-promised') | ||
const service = require('../../src/modules/usersSkill/service') | ||
const sinon = require('sinon') | ||
const app = require('../../app') | ||
const commonData = require('./common/commonData') | ||
|
||
chai.use(chaiHttp) | ||
chai.use(chaiAsPromised) | ||
const should = chai.should() | ||
const expect = chai.expect | ||
|
||
describe('Unit tests for /users/{userId}/skills', () => { | ||
afterEach(() => { | ||
sinon.restore() | ||
}) | ||
describe('Test GET', () => { | ||
beforeEach(() => { | ||
sinon.stub(service, 'search').resolves({ | ||
page: 1, | ||
perPage: 20, | ||
total: 1, | ||
result: [{ | ||
id: 1, | ||
userId: 1, | ||
skillId: 1 | ||
}] | ||
}) | ||
}) | ||
for (const tokenName of ['admin', 'administrator', 'topcoderUser', 'copilot', 'ubahn']) { | ||
it(`Call GET API with ${tokenName} token successfully`, async () => { | ||
const response = await chai.request(app).get(`/${config.API_VERSION}/users/test_user/skills`) | ||
.set('Authorization', 'Bearer ' + commonData[`${tokenName}Token`]) | ||
should.equal(response.status, 200) | ||
should.equal(response.headers['x-page'], '1') | ||
should.equal(response.headers['x-per-page'], '20') | ||
should.equal(response.headers['x-total'], '1') | ||
should.equal(response.headers['x-total-pages'], '1') | ||
should.exist(response.headers.link) | ||
should.equal(response.body.length, 1) | ||
}) | ||
} | ||
it('Call GET API with other token', async () => { | ||
const response = await chai.request(app).get(`/${config.API_VERSION}/users/test_user/skills`) | ||
.set('Authorization', `Bearer ${commonData.unKnownToken}`) | ||
should.equal(response.status, 403) | ||
}) | ||
it('Call GET API without token', async () => { | ||
const response = await chai.request(app).get(`/${config.API_VERSION}/users/test_user/skills`) | ||
should.equal(response.status, 403) | ||
}) | ||
}) | ||
describe('Test HEAD', () => { | ||
beforeEach(() => { | ||
sinon.stub(service, 'search').resolves({ | ||
page: 1, | ||
perPage: 20, | ||
total: 1, | ||
result: [{ | ||
id: 1, | ||
userId: 1, | ||
skillId: 1 | ||
}] | ||
}) | ||
}) | ||
for (const tokenName of ['admin', 'administrator', 'topcoderUser', 'copilot', 'ubahn']) { | ||
it(`Call HEAD API with ${tokenName} token successfully`, async () => { | ||
const response = await chai.request(app).head(`/${config.API_VERSION}/users/test_user/skills`) | ||
.set('Authorization', 'Bearer ' + commonData[`${tokenName}Token`]) | ||
should.equal(response.status, 200) | ||
should.equal(response.headers['x-page'], '1') | ||
should.equal(response.headers['x-per-page'], '20') | ||
should.equal(response.headers['x-total'], '1') | ||
should.equal(response.headers['x-total-pages'], '1') | ||
should.exist(response.headers.link) | ||
should.equal(_.isEmpty(response.body), true) | ||
}) | ||
} | ||
it('Call HEAD API with other token', async () => { | ||
const response = await chai.request(app).head(`/${config.API_VERSION}/users/test_user/skills`) | ||
.set('Authorization', `Bearer ${commonData.unKnownToken}`) | ||
should.equal(response.status, 403) | ||
}) | ||
it('Call HEAD API without token', async () => { | ||
const response = await chai.request(app).head(`/${config.API_VERSION}/users/test_user/skills`) | ||
should.equal(response.status, 403) | ||
}) | ||
}) | ||
describe('Test POST', () => { | ||
const userSkill = { | ||
userId: 'string', | ||
skillId: 'string', | ||
metricValue: 'string', | ||
certifierId: 'string', | ||
certifiedDate: '2021-10-11T10:59:12.816Z', | ||
created: '2021-10-11T10:59:12.816Z', | ||
updated: '2021-10-11T10:59:12.817Z', | ||
createdBy: 'string', | ||
updatedBy: 'string' | ||
} | ||
let stubCreate | ||
beforeEach(() => { | ||
stubCreate = sinon.stub(service, 'create').resolves(userSkill) | ||
}) | ||
for (const tokenName of ['admin', 'administrator', 'topcoderUser', 'copilot', 'ubahn']) { | ||
it(`Call POST API with ${tokenName} token successfully`, async () => { | ||
const response = await chai.request(app).post(`/${config.API_VERSION}/users/test_user/skills`) | ||
.set('Authorization', 'Bearer ' + commonData[`${tokenName}Token`]) | ||
.send({ skillId: 'testSkill' }) | ||
should.equal(response.status, 200) | ||
expect(response.body).to.deep.eq(userSkill) | ||
should.equal(stubCreate.calledOnce, true) | ||
expect(stubCreate.getCall(0).args[0]).to.deep.eq({ userId: 'test_user', skillId: 'testSkill' }) | ||
}) | ||
} | ||
it('Call POST API with other token', async () => { | ||
const response = await chai.request(app).post(`/${config.API_VERSION}/users/test_user/skills`) | ||
.set('Authorization', `Bearer ${commonData.unKnownToken}`) | ||
.send({ skillId: 'testSkill' }) | ||
should.equal(response.status, 403) | ||
}) | ||
it('Call POST API without token', async () => { | ||
const response = await chai.request(app).post(`/${config.API_VERSION}/users/test_user/skills`) | ||
.send({ skillId: 'testSkill' }) | ||
should.equal(response.status, 403) | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
const _ = require('lodash') | ||
const chai = require('chai') | ||
const chaiAsPromised = require('chai-as-promised') | ||
const sinon = require('sinon') | ||
const sequelize = require('../../src/models/index') | ||
const service = require('../../src/modules/usersSkill/service') | ||
const helper = require('../../src/common/helper') | ||
const serviceHelper = require('../../src/common/service-helper') | ||
const dbHelper = require('../../src/common/db-helper') | ||
const errors = require('../../src/common/errors') | ||
|
||
chai.use(chaiAsPromised) | ||
const expect = chai.expect | ||
|
||
describe('user skills service test', () => { | ||
beforeEach(() => { | ||
sinon.stub(sequelize, 'transaction').callsFake(f => f()) | ||
}) | ||
afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
describe('Create user skills', () => { | ||
it('Create user skills successfully', async () => { | ||
const entity = { userId: 'userId', skillId: 'skillId' } | ||
const newEntity = _.assign({ createdBy: 'test' }, entity) | ||
sinon.stub(dbHelper, 'get').resolves({}) | ||
sinon.stub(dbHelper, 'makeSureUnique').resolves({}) | ||
const stubDBCreate = sinon.stub(dbHelper, 'create').resolves({ toJSON: () => newEntity }) | ||
const stubEsInsert = sinon.stub(serviceHelper, 'createRecordInEs').resolves({}) | ||
const result = await service.create(entity, {}) | ||
expect(result).to.deep.eql(newEntity) | ||
expect(stubDBCreate.calledOnce).to.be.true | ||
expect(stubEsInsert.calledOnce).to.be.true | ||
expect(stubDBCreate.getCall(0).args[1]).to.deep.eq(entity) | ||
expect(stubEsInsert.getCall(0).args[1]).to.deep.eq(newEntity) | ||
}) | ||
it('Throw error when require parameters absence', async () => { | ||
await expect(service.create({ userId: 'userId' })).to.be.rejectedWith('"entity.skillId" is required') | ||
await expect(service.create({ skillId: 'skillId' })).to.be.rejectedWith('"entity.userId" is required') | ||
}) | ||
it('Throw error when user id does not exist', async () => { | ||
const error = errors.newEntityNotFoundError('cannot find user where id:userId') | ||
sinon.stub(dbHelper, 'get').rejects(error) | ||
await expect(service.create({ userId: 'userId', skillId: 'skillId' })).to.eventually.rejectedWith(error) | ||
}) | ||
it('Throw error when a record with same user id and skill id exist', async () => { | ||
const error = errors.newConflictError('usersSkill already exists with userId:userId,skillId:skillId') | ||
sinon.stub(dbHelper, 'get').resolves({}) | ||
sinon.stub(dbHelper, 'makeSureUnique').rejects(error) | ||
await expect(service.create({ userId: 'userId', skillId: 'skillId' })).to.eventually.rejectedWith(error) | ||
}) | ||
it('Throw error and does not publish error event when insert into db error', async () => { | ||
const error = new Error('db error') | ||
sinon.stub(dbHelper, 'get').resolves({}) | ||
sinon.stub(dbHelper, 'makeSureUnique').resolves({}) | ||
const stubPublishError = sinon.stub(helper, 'publishError') | ||
sinon.stub(dbHelper, 'create').rejects(error) | ||
await expect(service.create({ userId: 'userId', skillId: 'skillId' })).to.eventually.rejectedWith(error) | ||
expect(stubPublishError.called).to.be.false | ||
}) | ||
it('Throw error and publish error event when insert into es error', async () => { | ||
const error = new Error('es error') | ||
const entity = { userId: 'userId', skillId: 'skillId' } | ||
const newEntity = _.assign({ createdBy: 'test' }, entity) | ||
sinon.stub(dbHelper, 'get').resolves({}) | ||
sinon.stub(dbHelper, 'makeSureUnique').resolves({}) | ||
const stubPublishError = sinon.stub(helper, 'publishError').resolves({}) | ||
const stubDBCreate = sinon.stub(dbHelper, 'create').resolves({ toJSON: () => newEntity }) | ||
sinon.stub(serviceHelper, 'createRecordInEs').rejects(error) | ||
await expect(service.create({ userId: 'userId', skillId: 'skillId' })).to.eventually.rejectedWith(error) | ||
expect(stubPublishError.called).to.be.true | ||
expect(stubDBCreate.called).to.be.true | ||
}) | ||
}) | ||
describe('Search user skills', () => { | ||
it('Throw error when require parameters absence', async () => { | ||
await expect(service.search({ })).to.be.rejectedWith(errors.BadRequestError) | ||
}) | ||
it('Throw error when user id does not exist', async () => { | ||
const error = errors.newEntityNotFoundError('cannot find user where id:userId') | ||
sinon.stub(dbHelper, 'get').rejects(error) | ||
await expect(service.search({ userId: 'userId' })).to.eventually.rejectedWith(error) | ||
}) | ||
it('Search user skills from es successfully', async () => { | ||
const entity = { userId: 'userId', skillId: 'skillId' } | ||
const newEntity = _.assign({ createdBy: 'test' }, entity) | ||
sinon.stub(dbHelper, 'get').resolves({}) | ||
const searchEs = sinon.stub(serviceHelper, 'searchRecordInEs').resolves([newEntity]) | ||
const searchDb = sinon.stub(dbHelper, 'find') | ||
const result = await service.search({ userId: 'userId' }, {}) | ||
expect(result).to.deep.eql([newEntity]) | ||
expect(searchEs.calledOnce).to.be.true | ||
expect(searchDb.called).to.be.false | ||
}) | ||
it('Search user skills from db when es throw errors', async () => { | ||
const entity = { userId: 'userId', skillId: 'skillId' } | ||
const newEntity = _.assign({ createdBy: 'test' }, entity) | ||
sinon.stub(dbHelper, 'get').resolves({}) | ||
const searchEs = sinon.stub(serviceHelper, 'searchRecordInEs').resolves(null) | ||
const searchDb = sinon.stub(dbHelper, 'find').resolves([newEntity]) | ||
const result = await service.search({ userId: 'userId' }, {}) | ||
expect(result).to.deep.eql({ fromDb: true, result: [newEntity], total: 1 }) | ||
expect(searchEs.calledOnce).to.be.true | ||
expect(searchDb.called).to.be.true | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Sande3p I don't see any update in the code where
setUserSearchClausesToEsQuery
is used. I mean if we have removed searching skills in this method's implementation, we must be doing that where this function is being called, right? Am I missing something here?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, I don't think we need to do anything in
searchUsers
, the keyword be used to match user records. since we remove skill model, we just remove the matching skill name and reserve other matchings.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.
What I meant is
searchUsers
method would not support searching by skills name now, if we don't add some other way to provide filtering for user based on skills names. I want to be sure that we are not removing any feature from the calling code. We need to remove skills model but we should not remove any feature from the calling code.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.
fixed