Skip to content

Commit

Permalink
Merge pull request #510 from Duke-MatSci/resolve_ns
Browse files Browse the repository at this point in the history
Resolve Namespace - Pt1
  • Loading branch information
tholulomo authored Aug 15, 2024
2 parents 5d7d66c + e797b3b commit d4f2f41
Show file tree
Hide file tree
Showing 13 changed files with 737 additions and 442 deletions.
29 changes: 29 additions & 0 deletions app/src/pages/ns/Home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div class="section_pages">
<div v-if="!loading && !namespace" class="wrapper">
<h1 class="visualize_header-h1 article_title">
MaterialsMine Namespace Center
</h1>
<div class="article_subtitle">Welcome...</div>
</div>
<div v-else-if="!loading && namespace" class="wrapper">
<h1 class="visualize_header-h1 article_title">{{ namespace }}</h1>
<div class="article_subtitle">Additional information comming soon...</div>
</div>
</div>
</template>
<script>
export default {
name: 'Namespace',
data () {
return {
loading: false
}
},
computed: {
namespace () {
return this.$route.params?.namespace
}
}
}
</script>
6 changes: 6 additions & 0 deletions app/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import metamineRoutes from '@/router/module/metamine'
import explorerRoutes from '@/router/module/explorer'
import portalRoutes from '@/router/module/portal'
import xsdRoutes from '@/router/module/xsd'
import nsRoutes from './module/ns'
Vue.use(VueRouter)

const routes = [
Expand All @@ -25,6 +26,11 @@ const routes = [
component: NanomineBase,
children: [...nanomineRoutes]
},
{
path: '/ns',
component: ExplorerBase,
children: [...nsRoutes]
},
{
path: '/mm',
component: MetamineBase,
Expand Down
4 changes: 3 additions & 1 deletion app/src/router/module/explorer.js
Original file line number Diff line number Diff line change
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
16 changes: 16 additions & 0 deletions app/src/router/module/ns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const nsRoutes = [
{
path: '',
name: 'Namespace',
component: () => import('@/pages/ns/Home.vue'),
meta: { requiresAuth: false }
},
{
path: ':namespace',
name: 'Namespaces',
component: () => import('@/pages/ns/Home.vue'),
meta: { requiresAuth: false }
}
]

export default nsRoutes
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: '[email protected]',
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: '[email protected]',
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 d4f2f41

Please sign in to comment.