Skip to content

Commit

Permalink
feat(#509): Refactoring mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
tholulomo committed Aug 13, 2024
1 parent eee1f11 commit 5f15d81
Show file tree
Hide file tree
Showing 10 changed files with 690 additions and 446 deletions.
12 changes: 7 additions & 5 deletions app/src/router/module/explorer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ChartBase from '@/pages/explorer/chart/Base.vue'
import ImageBase from '@/pages/explorer/image/Base.vue'
import ChartBase from '@/pages/explorer/chart/Base.vue';
import ImageBase from '@/pages/explorer/image/Base.vue';
const explorerRoutes = [
{
path: '',
Expand Down Expand Up @@ -134,7 +134,9 @@ const explorerRoutes = [
{
path: '',
name: 'validList',
component: () => import('@/pages/explorer/curate/validlist/XlsList.vue')
component: () =>
import('@/pages/explorer/curate/validlist/XlsList.vue'),
meta: { requiresAuth: true }
},
{
path: 'update',
Expand Down Expand Up @@ -295,6 +297,6 @@ const explorerRoutes = [
}
]
}
]
];

export default explorerRoutes
export default explorerRoutes;
2 changes: 1 addition & 1 deletion resfulservice/spec/controllers/curationController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('Curation Controller', function () {
const nextSpy = sinon.spy();
sinon.stub(res, 'status').returnsThis();
sinon.stub(res, 'json').returnsThis();
sinon.stub(DatasetId, 'findOne').throws();
sinon.stub(XlsxObject, 'find').throws();

await XlsxController.getControlSampleId(req, res, nextSpy);
sinon.assert.calledOnce(nextSpy);
Expand Down
148 changes: 70 additions & 78 deletions resfulservice/spec/graphql/resolver/comment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,29 @@ const chai = require('chai');
const sinon = require('sinon');
const Comment = require('../../../src/models/comment');
const graphQlSchema = require('../../../src/graphql');
const { Mutation: { postComment, editComment }, Query: { loadComment }} = require('../../../src/graphql/resolver');

const {
Mutation: { postComment, editComment },
Query: { loadComment }
} = require('../../../src/graphql/resolver');
const {
mockCommentList,
mockDBComment,
mockCommentInput,
mockComment,
user
} = require('../../mocks');

const { expect } = chai;
const user = {
_id: 'ai094oja09aw40-o',
displayName: "test"
}
const mockComment = {
"comment": "test comment",
"type": "xml",
"identifier": "64394c8032bc6325505af6f9",
"user": "64394c8032bc6325505af6f9"
}

const mockCommentInput = {
"id": "64394c8032bc6325505af6f9",
"comment": "test comment",
"type": "xml",
"identifier": "64394c8032bc6325505af6f9"
}

const mockDBComment = {
"user": {
"givenName": "Test",
"surName": "Test"
},
...mockComment,
lean: () => this,
populate: sinon.stub().returnsThis()
}

const mockCommentList = [
{
"_id": "64397a5cdffb639553bf62e4",
"comment": "first comment",
"user": {
"givenName": "Test",
"surName": "Test"
},
"createdAt": "1681488476581",
"updatedAt": "1681489494515"
},
{
"_id": "64397a5cdffb639553bf62e4",
"comment": "secont comment",
"user": {
"givenName": "Test",
"surName": "Test"
},
"createdAt": "1681488476581",
"updatedAt": "1681489494515"
}
]

describe('Comment Resolver Unit Tests:', function () {

afterEach(() => sinon.restore());

const req = { logger: { info: (message) => { }, error: (message) => { } } }
const req = { logger: { info: (message) => {}, error: (message) => {} } };

context('postComment', () => {
const input = {
...mockCommentInput
}
};

it('should have postComment(...) as a Mutation resolver', async function () {
const { postComment } = graphQlSchema.getMutationType().getFields();
Expand All @@ -79,24 +37,35 @@ describe('Comment Resolver Unit Tests:', function () {
});

it('should create new comment', async () => {
sinon.stub(Comment.prototype, 'save').callsFake(() => (mockDBComment))
sinon.stub(Comment.prototype, 'save').callsFake(() => mockDBComment);
// sinon.stub(MaterialTemplate.prototype, 'save').callsFake(() => ({...input, _id: 'b39ak9qna'}))
const comment = await postComment({}, { input }, { user, req, isAuthenticated: true });
const comment = await postComment(
{},
{ input },
{ user, req, isAuthenticated: true }
);

expect(comment).to.have.property('comment');
});

it('should return a 401 unauthenticated error', async () => {

const result = await postComment({}, { input: { } }, { user, req, isAuthenticated: false });
const result = await postComment(
{},
{ input: {} },
{ user, req, isAuthenticated: false }
);

expect(result).to.have.property('extensions');
expect(result.extensions.code).to.be.equal(401);
});

it("should throw a 500, server error", async () => {
it('should throw a 500, server error', async () => {
sinon.stub(Comment.prototype, 'save').throws();
const error = await postComment({}, { input }, { user, req, isAuthenticated: true });
const error = await postComment(
{},
{ input },
{ user, req, isAuthenticated: true }
);

expect(error).to.have.property('extensions');
expect(error.extensions.code).to.be.equal(500);
Expand All @@ -106,63 +75,86 @@ describe('Comment Resolver Unit Tests:', function () {
const { postComment } = graphQlSchema.getMutationType().getFields();
expect(postComment.type.toString()).to.equal('Comment!');
});
})
});

context('editComment', () => {
const input = { ...mockCommentInput }
it("should throw a 401, not authenticated error", async () => {

const error = await editComment({}, { input }, { user, req, isAuthenticated: false });
const input = { ...mockCommentInput };
it('should throw a 401, not authenticated error', async () => {
const error = await editComment(
{},
{ input },
{ user, req, isAuthenticated: false }
);
expect(error).to.have.property('extensions');
expect(error.extensions.code).to.be.equal(401);
});

it("should return a 404 error if column doesn't exist", async () => {
sinon.stub(Comment, 'findOneAndUpdate').returns(null);
const error = await editComment({}, { input }, { user, req, isAuthenticated: true });
const error = await editComment(
{},
{ input },
{ user, req, isAuthenticated: true }
);

expect(error).to.have.property('extensions');
expect(error.extensions.code).to.be.equal(404);
});

it("should update column if column exists", async () => {
sinon.stub(Comment, 'findOneAndUpdate').returns({...mockDBComment });
it('should update column if column exists', async () => {
sinon.stub(Comment, 'findOneAndUpdate').returns({ ...mockDBComment });

const result = await editComment({}, { input }, { user, req, isAuthenticated: true });
const result = await editComment(
{},
{ input },
{ user, req, isAuthenticated: true }
);

expect(result).to.have.property('comment');
expect(result).to.have.property('user');
});

it("should throw a 500, server error", async () => {
it('should throw a 500, server error', async () => {
sinon.stub(Comment, 'findOneAndUpdate').throws();
const error = await editComment({}, { input }, { user, req, isAuthenticated: true });
const error = await editComment(
{},
{ input },
{ user, req, isAuthenticated: true }
);

expect(error).to.have.property('extensions');
expect(error.extensions.code).to.be.equal(500);
});
});

context('loadComment', () => {
const input = { ...mockComment, pageNumber: 1, pageSize: 10 }
const input = { ...mockComment, pageNumber: 1, pageSize: 10 };

it("should return paginated lists of comments", async () => {
it('should return paginated lists of comments', async () => {
sinon.stub(Comment, 'countDocuments').returns(2);
sinon.stub(Comment, 'find').returns({
limit: sinon.stub().returnsThis(),
skip: sinon.stub().returns(mockCommentList)
});

const result = await loadComment({}, { input }, { user, req, isAuthenticated: true });
const result = await loadComment(
{},
{ input },
{ user, req, isAuthenticated: true }
);

expect(result).to.have.property('comments');
expect(result.comments).to.be.an('Array');
});

it("should throw a 500, server error", async () => {
sinon.stub(Comment, 'countDocuments').returns(2)
it('should throw a 500, server error', async () => {
sinon.stub(Comment, 'countDocuments').returns(2);
sinon.stub(Comment, 'find').throws();
const error = await loadComment({}, { input }, { user, req, isAuthenticated: true });
const error = await loadComment(
{},
{ input },
{ user, req, isAuthenticated: true }
);

expect(error).to.have.property('extensions');
expect(error.extensions.code).to.be.equal(500);
Expand Down
31 changes: 5 additions & 26 deletions resfulservice/spec/graphql/resolver/contact.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const chai = require('chai');
const sinon = require('sinon');
const Contact = require('../../../src/models/contact');
const graphQlSchema = require('../../../src/graphql');
const {
mockContact,
mockUserContact,
mockUpdatedContact
} = require('../../mocks');
const {
Mutation: { submitContact, updateContact },
Query: { getUserContacts, contacts }
Expand All @@ -11,23 +16,6 @@ const FileController = require('../../../src/controllers/fileController');

const { expect } = chai;

const mockContact = {
fullName: 'test user',
email: 'test@example.com',
purpose: 'QUESTION',
message: 'test message',
attachments: [
'/api/files/strategic_beetle_joelle-2024-02-15T09:25:42.264Z-master_template (5).xlsx?isStore=true',
'/api/files/strategic_beetle_joelle-2024-02-15T09:27:07.905Z-master_template.xlsx?isStore=true'
]
};

const mockUpdatedContact = {
...mockContact,
resolved: true,
response: 'Thanks for reaching out. We are working on it'
};

describe('Contact Resolver Unit Tests:', function () {
afterEach(() => sinon.restore());

Expand Down Expand Up @@ -124,15 +112,6 @@ describe('Contact Resolver Unit Tests:', function () {
});

context('getUserContacts', () => {
const mockUserContact = {
_id: 'akdn9wqkn',
fullName: 'test user',
email: 'test@example.com',
purpose: 'QUESTION',
message: 'test message',
lean: () => this
};

it("should return paginated lists of a user's contacts", async () => {
sinon.stub(Contact, 'countDocuments').returns(1);
sinon.stub(Contact, 'find').returns(mockUserContact);
Expand Down
Loading

0 comments on commit 5f15d81

Please sign in to comment.