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

added onlyForFemale field #76

Closed
Closed
11 changes: 11 additions & 0 deletions managers/opportunity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ class opportunityManager {
queryObject['opportunityType'] = queryObject.type;
delete queryObject.type;
}
if (queryObject.female) {
queryObject['onlyForFemale'] = queryObject.female == 'true';
Copy link
Member

Choose a reason for hiding this comment

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

should not this be a boolean value? and please use === instead of ==.

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!

delete queryObject.female;
}
console.log('Values in QueryString', queryObject);

let fetchedOpportunitiesQuery = this.opportunity.find(queryObject);
// fetchedOpportunitiesQuery.select('-__v');
// fetchedOpportunitiesQuery.select('-_id');
console.log(fetchedOpportunitiesQuery.data);
Copy link
Member

Choose a reason for hiding this comment

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

remove console.log(s). makes test output untidy.

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!

return fetchedOpportunitiesQuery;

//console.log('Values of QueryString', queryObject);

Expand Down
15 changes: 4 additions & 11 deletions routes/opportunity.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,12 @@ const opportunityManager = new OpportunityManager(),
* - SCHOLARSHIP
* - CONFERENCE
* - CODINGCOMPETITION
* description: Retrieve a list of opportunities based on particular type.
* description: Retrieve a list of opportunities based on particular type or only for female.
* parameters:
* - in: query
* name: page
* name: female
* schema:
* type: Integer
* default: 1
* description: The Current Page for which the data User Wants
* - in: query
* name: limit
* schema:
* type: Integer
* default: 10
* description: The count of items/documents that should be returned on each page
Copy link
Member

Choose a reason for hiding this comment

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

this one

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!

* type: boolean
* responses:
* 200:
* description: A list of opportunities.
Expand Down
1 change: 1 addition & 0 deletions tests/controller/opportunity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('OpportunityController', function () {
req = {
query: {
type: stubValue.opportunityType,
female: stubValue.onlyForFemale,
},
};
status = sinon.stub();
Expand Down
77 changes: 6 additions & 71 deletions tests/managers/opportunity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import sinon from 'sinon';
import stubValue from '../fakedata.js';
import Opportunity from '../../models/opportunity.js';
import OpportunityManager from '../../managers/opportunity/index.js';

describe('OpportunityManager', function () {
describe('createOpportunity', function () {
it('should add a new Opportunity to the Opportunity database', async function () {
Expand All @@ -19,8 +18,7 @@ describe('OpportunityManager', function () {
stubValue.opportunityRegistrationDeadline,
stubValue.opportunityDate,
stubValue.opportunityURL,
stubValue.onlyForFemale ,
stubValue.organisationLogoURL
stubValue.onlyForFemale
);
expect(stub.calledOnce).to.be.true;
expect(opportunity.opportunityTitle).to.equal(stubValue.opportunityTitle);
Expand All @@ -41,26 +39,17 @@ describe('OpportunityManager', function () {
expect(opportunity.opportunityURL).to.equal(stubValue.opportunityURL);
expect(opportunity.createdAt).to.equal(stubValue.createdAt);
expect(opportunity.updatedAt).to.equal(stubValue.updatedAt);
expect(opportunity.organisationLogoURL).to.equal(stubValue.organisationLogoURL) ;
});
});

describe('getOpportunities', function () {
it('should retrieve Opportunities with specific opportunityType', async function () {
const stub = sinon.stub(Opportunity, 'find').returns(stubValue);
const stubCountDocuments = sinon.stub(Opportunity, 'countDocuments').returns({
exec : async () => 10
});

const opportunityManager = new OpportunityManager();
const opportunity = (
await opportunityManager.getOpportunities({
type: stubValue.opportunityType,
})
).results;


expect(stubCountDocuments.calledOnce).to.be.true;
const opportunity = await opportunityManager.getOpportunities({
type: stubValue.opportunityType,
female: stubValue.onlyForFemale
});
expect(stub.calledOnce).to.be.true;
expect(opportunity.opportunityTitle).to.equal(stubValue.opportunityTitle);
expect(opportunity.opportunityType).to.equal(stubValue.opportunityType);
Expand All @@ -80,61 +69,7 @@ describe('OpportunityManager', function () {
expect(opportunity.opportunityURL).to.equal(stubValue.opportunityURL);
expect(opportunity.createdAt).to.equal(stubValue.createdAt);
expect(opportunity.updatedAt).to.equal(stubValue.updatedAt);
expect(opportunity.organisationLogoURL).to.equal(stubValue.organisationLogoURL) ;
expect(opportunity.onlyForFemale).to.equal(stubValue.onlyForFemale);
});
});

describe('updateOpportunity', function () {
it('should update existing Opportunity', async function () {
const stub = sinon.stub(Opportunity, 'updateOne').returns(stubValue);
const opportunityManager = new OpportunityManager();
const queryObject = { _id: stubValue._id };
const updatingobject = {
opportunityTitle: stubValue.opportunityTitle,
opportunityType: stubValue.opportunityType,
opportunityOrganisation: stubValue.opportunityOrganisation,
opportunityLocation: stubValue.opportunityLocation,
opportunityDescription: stubValue.opportunityDescription,
opportunityEligibility: stubValue.opportunityEligibility,
opportunityRegistrationDeadline:
stubValue.opportunityRegistrationDeadline,
opportunityDate: stubValue.opportunityDate,
opportunityURL: stubValue.opportunityURL,
organisationLogoURL: stubValue.organisationLogoURL,
};
const updatedOpportunity = await opportunityManager.updateOpportunity(
queryObject,
updatingobject
);
expect(stub.calledOnce).to.be.true;

expect(updatedOpportunity.opportunityTitle).to.equal(
stubValue.opportunityTitle
);
expect(updatedOpportunity.opportunityType).to.equal(
stubValue.opportunityType
);
expect(updatedOpportunity.opportunityOrganisation).to.equal(
stubValue.opportunityOrganisation
);
expect(updatedOpportunity.opportunityLocation).to.equal(
stubValue.opportunityLocation
);
expect(updatedOpportunity.opportunityDescription).to.equal(
stubValue.opportunityDescription
);
expect(updatedOpportunity.opportunityRegistrationDeadline).to.equal(
stubValue.opportunityRegistrationDeadline
);
expect(updatedOpportunity.opportunityDate).to.equal(
stubValue.opportunityDate
);
expect(updatedOpportunity.opportunityURL).to.equal(
stubValue.opportunityURL
);
expect(updatedOpportunity.createdAt).to.equal(stubValue.createdAt);
expect(updatedOpportunity.updatedAt).to.equal(stubValue.updatedAt);
expect(updatedOpportunity.organisationLogoURL).to.equal(stubValue.organisationLogoURL);
});
});
});
3 changes: 3 additions & 0 deletions tests/services/opportunity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('OpportunityService', function () {
expect(stub.calledOnce).to.be.true;
expect(opportunity.opportunityTitle).to.equal(stubValue.opportunityTitle);
expect(opportunity.opportunityType).to.equal(stubValue.opportunityType);
expect(opportunity.onlyForFemale).to.equal(stubValue.onlyForFemale);
expect(opportunity.opportunityOrganisation).to.equal(
stubValue.opportunityOrganisation
);
Expand Down Expand Up @@ -57,10 +58,12 @@ describe('OpportunityService', function () {
const opportunityService = new OpportunityService(opportunityManager);
const opportunity = await opportunityService.getOpportunities({
type: stubValue.opportunityType,
female: stubValue.onlyForFemale,
});
expect(stub.calledOnce).to.be.true;
expect(opportunity.opportunityTitle).to.equal(stubValue.opportunityTitle);
expect(opportunity.opportunityType).to.equal(stubValue.opportunityType);
expect(opportunity.onlyForFemale).to.equal(stubValue.onlyForFemale);
expect(opportunity.opportunityOrganisation).to.equal(
stubValue.opportunityOrganisation
);
Expand Down