diff --git a/app/src/pages/ns/Home.vue b/app/src/pages/ns/Home.vue new file mode 100644 index 00000000..c2e358b2 --- /dev/null +++ b/app/src/pages/ns/Home.vue @@ -0,0 +1,29 @@ + + diff --git a/app/src/router/index.js b/app/src/router/index.js index 8a50ae68..8bd59c10 100644 --- a/app/src/router/index.js +++ b/app/src/router/index.js @@ -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 = [ @@ -25,6 +26,11 @@ const routes = [ component: NanomineBase, children: [...nanomineRoutes] }, + { + path: '/ns', + component: ExplorerBase, + children: [...nsRoutes] + }, { path: '/mm', component: MetamineBase, diff --git a/app/src/router/module/explorer.js b/app/src/router/module/explorer.js index 2e57ccfb..399c9a3c 100644 --- a/app/src/router/module/explorer.js +++ b/app/src/router/module/explorer.js @@ -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', diff --git a/app/src/router/module/ns.js b/app/src/router/module/ns.js new file mode 100644 index 00000000..c8230dbc --- /dev/null +++ b/app/src/router/module/ns.js @@ -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 diff --git a/resfulservice/spec/controllers/curationController.spec.js b/resfulservice/spec/controllers/curationController.spec.js index c42a45fc..349d302f 100644 --- a/resfulservice/spec/controllers/curationController.spec.js +++ b/resfulservice/spec/controllers/curationController.spec.js @@ -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); diff --git a/resfulservice/spec/graphql/resolver/comment.spec.js b/resfulservice/spec/graphql/resolver/comment.spec.js index 4468474e..77a02325 100644 --- a/resfulservice/spec/graphql/resolver/comment.spec.js +++ b/resfulservice/spec/graphql/resolver/comment.spec.js @@ -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(); @@ -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); @@ -106,37 +75,52 @@ 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); @@ -144,25 +128,33 @@ describe('Comment Resolver Unit Tests:', function () { }); 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); diff --git a/resfulservice/spec/graphql/resolver/contact.spec.js b/resfulservice/spec/graphql/resolver/contact.spec.js index cdbc7678..7576f364 100644 --- a/resfulservice/spec/graphql/resolver/contact.spec.js +++ b/resfulservice/spec/graphql/resolver/contact.spec.js @@ -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 } @@ -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()); @@ -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); diff --git a/resfulservice/spec/graphql/resolver/dataset.spec.js b/resfulservice/spec/graphql/resolver/dataset.spec.js index e1bebb09..8b428d1a 100644 --- a/resfulservice/spec/graphql/resolver/dataset.spec.js +++ b/resfulservice/spec/graphql/resolver/dataset.spec.js @@ -4,90 +4,19 @@ const DatasetId = require('../../../src/models/datasetId'); const Dataset = require('../../../src/models/dataset'); const User = require('../../../src/models/user'); const graphQlSchema = require('../../../src/graphql'); -const { Mutation: { createDatasetId, createDataset }, Query: { getUserDataset, getFilesets }} = require('../../../src/graphql/resolver'); - +const { + Mutation: { createDatasetId, createDataset }, + Query: { getUserDataset, getFilesets } +} = require('../../../src/graphql/resolver'); +const { user, mockDataset, mockFiles } = require('../../mocks'); const { expect } = chai; - describe('Dataset Resolver Unit Tests:', function () { - afterEach(() => sinon.restore()); - this.timeout(10000) + this.timeout(10000); - const input = { - doi: 'unpublished/doi-tMbKM2ba5aNwo2ZKPVucBS', - datasetId: '62fce36374da548513a38a9b', - files: [ - { - fieldname: 'uploadfile', - originalname: 'Hopetoun_falls.jpg', - encoding: '7bit', - mimetype: 'image/jpeg', - destination: 'mm_files', - filename: 'comparative_aphid_agathe-2022-08-18T10:00:40.910Z-Hopetoun_falls.jpg', - path: 'mm_files/comparative_aphid_agathe-2022-08-18T10:00:40.910Z-Hopetoun_falls.jpg', - size: 2954043, - }, - { - fieldname: 'uploadfile', - originalname: 'flowers-276014__340.jpg', - encoding: '7bit', - mimetype: 'image/jpeg', - destination: 'mm_files', - filename: 'comparative_aphid_agathe-2022-08-18T10:00:41.018Z-flowers-276014__340.jpg', - path: 'mm_files/comparative_aphid_agathe-2022-08-18T10:00:41.018Z-flowers-276014__340.jpg', - size: 56575, - }, - ], - } - - - - const mockDataset = { - _id: "62f11b1328eedaab012d127c", - datasetId: "62f11b1328eedaab012d127c", - userid: "62f119fb28eedaab012d1262", - filesets: [ - { - fileset: 'E109_S2_Huang_2016', - files: [ - { - type: 'blob', - id: '5b51f112e74a1d4cdbad6a1d', - metadata: { - filename: '4.tif', - contentType: 'image/tiff', - }, - }, - { - type: 'blob', - id: '5b51f137e74a1d4cdbad6a3a', - metadata: { - filename: '5.tif', - contentType: 'image/tiff', - }, - }, - ], - }, - ], - skip: sinon.stub().returnsThis(), - limit: sinon.stub().returnsThis(), - lean: sinon.stub().returnsThis() - } - - const user = { - _id: '62dab1b76db8739c8330611d', - alias: 'testalias', - givenName: 'test', - surName: 'test user', - displayName: 'tester', - userid: '62dab1b76db8739c8330611d', - email: 'test@example.com', - roles: 'member' - } - - const req = { logger: { info: (message) => { }, error: (message) => { } } } + const req = { logger: { info: (message) => {}, error: (message) => {} } }; context('createDatasetId', () => { it('should have createDatasetId(...) as a Mutation resolver', async function () { @@ -95,39 +24,61 @@ describe('Dataset Resolver Unit Tests:', function () { expect(createDatasetId.name).to.equal('createDatasetId'); expect(createDatasetId.type.toString()).to.equal('Datasets!'); }); - - it("should throw a 401, not authenticated error", async () => { - const result = await createDatasetId({}, { }, { user, req, isAuthenticated: false }); + + it('should throw a 401, not authenticated error', async () => { + const result = await createDatasetId( + {}, + {}, + { user, req, isAuthenticated: false } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(401) + expect(result.extensions.code).to.be.equal(401); }); it('should create a new datasetId', async () => { sinon.stub(DatasetId, 'findOne').returns(null); - sinon.stub(DatasetId.prototype, 'save').callsFake(() => ({_id: '62d951cb6981a12d136a0a0d', status: 'WORK IN PROGRESS', samples: [] })) - - const datasetId = await createDatasetId({}, {}, { user, req, isAuthenticated: true }); + sinon.stub(DatasetId.prototype, 'save').callsFake(() => ({ + _id: '62d951cb6981a12d136a0a0d', + status: 'WORK IN PROGRESS', + samples: [] + })); + + const datasetId = await createDatasetId( + {}, + {}, + { user, req, isAuthenticated: true } + ); expect(datasetId).to.have.property('datasetGroupId'); - }); - + }); - it("should throw a 409, when an unused datasetId exists", async () => { - sinon.stub(DatasetId, 'findOne').returns({_id: '62d951cb6981a12d136a0a0d', status: 'WORK IN PROGRESS', samples: [] }) - const result = await createDatasetId({}, { }, { user, req, isAuthenticated: true }); + it('should throw a 409, when an unused datasetId exists', async () => { + sinon.stub(DatasetId, 'findOne').returns({ + _id: '62d951cb6981a12d136a0a0d', + status: 'WORK IN PROGRESS', + samples: [] + }); + const result = await createDatasetId( + {}, + {}, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(409) + expect(result.extensions.code).to.be.equal(409); }); - it('should throw a 500 Internal server error when error is thrown', async () => { sinon.stub(DatasetId, 'findOne').throws(); - const result = await createDatasetId({}, { }, { user, req, isAuthenticated: true }); + const result = await createDatasetId( + {}, + {}, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(500) + expect(result.extensions.code).to.be.equal(500); }); it('should return DatasetId! datatype for createDatasetId(...) mutation', () => { @@ -137,33 +88,31 @@ describe('Dataset Resolver Unit Tests:', function () { }); context('getUserDataset', () => { - const mockDatasetId = { - _id: '9q4kn9898ani4a8n49hn49nv49', - dataset: mockDataset, - user, - status: 'WORK_IN_PROGRESS', - lean: () => this, - populate: () => this, - limit: () => this - } const input = { pageNumber: 1, pageSize: 10, status: 'APPROVED' - } + }; it("should return paginated lists of a user's datasets", async () => { sinon.stub(Dataset, 'find').returns(mockDataset); sinon.stub(Dataset, 'countDocuments').returns(1); sinon.stub(User, 'findOne').returns(user); - const datasets = await getUserDataset({}, { input }, { user, req, isAuthenticated: true }); + const datasets = await getUserDataset( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(datasets).to.have.property('datasets'); expect(datasets.totalItems).to.equal(1); }); - it("should throw a 401, not authenticated error", async () => { - - const error = await getUserDataset({}, { input }, { user, req, isAuthenticated: false }); + it('should throw a 401, not authenticated error', async () => { + const error = await getUserDataset( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: false } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(401); }); @@ -171,55 +120,77 @@ describe('Dataset Resolver Unit Tests:', function () { it('should return a 500 error', async () => { sinon.stub(Dataset, 'find').throws(); - const result = await getUserDataset({}, { input }, { user, req, isAuthenticated: true }); + const result = await getUserDataset( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(500) + expect(result.extensions.code).to.be.equal(500); }); }); context('getFilesets', () => { - const mockFilesetAggregate = [{ - count: 1, - filesets: mockDataset.filesets - }]; + const mockFilesetAggregate = [ + { + count: 1, + filesets: mockDataset.filesets + } + ]; const filesetInput = { - ...input, + ...mockFiles, pageSize: 10, pageNumber: 1 - } - it("should return file list of a fileset when both datasetId and filesetName are provided", async () => { + }; + it('should return file list of a fileset when both datasetId and filesetName are provided', async () => { sinon.stub(Dataset, 'aggregate').returns(mockFilesetAggregate); - // sinon.stub(mockDataset, 'lean').returnsThis(); - const fileset = await getFilesets({}, { input: { ...input, filesetName: 'E109_S2_Huang_2016' } }, { user, req, isAuthenticated: true }); + // sinon.stub(mockDataset, 'lean').returnsThis(); + const fileset = await getFilesets( + {}, + { input: { ...mockFiles, filesetName: 'E109_S2_Huang_2016' } }, + { user, req, isAuthenticated: true } + ); expect(fileset).to.have.property('filesetName'); expect(fileset).to.have.property('files'); expect(fileset.files).to.be.an('array'); - }); - it("should return file list of a fileset when only datasetId is provided", async () => { + it('should return file list of a fileset when only datasetId is provided', async () => { sinon.stub(Dataset, 'aggregate').returns(mockFilesetAggregate); - const filesetGroup = await getFilesets({}, { input: filesetInput }, { user, req, isAuthenticated: true }); + const filesetGroup = await getFilesets( + {}, + { input: filesetInput }, + { user, req, isAuthenticated: true } + ); expect(filesetGroup).to.have.property('filesets'); expect(filesetGroup.filesets).to.be.an('array'); expect(filesetGroup).to.have.property('pageSize'); }); - it("should return an aggregated list of a fileset when only filesetName is provided", async () => { - sinon.stub(Dataset, 'aggregate').returns([{filesets: mockDataset.filesets}]); - const fileset = await getFilesets({}, {input: { filesetName: 'E109_S2_Huang_2016' } }, { user, req, isAuthenticated: true }); + it('should return an aggregated list of a fileset when only filesetName is provided', async () => { + sinon + .stub(Dataset, 'aggregate') + .returns([{ filesets: mockDataset.filesets }]); + const fileset = await getFilesets( + {}, + { input: { filesetName: 'E109_S2_Huang_2016' } }, + { user, req, isAuthenticated: true } + ); expect(fileset).to.have.property('filesetName'); expect(fileset).to.have.property('files'); expect(fileset.files).to.be.an('array'); }); - it("should throw a 401, not authenticated error", async () => { - - const error = await getFilesets({}, { input }, { user, req, isAuthenticated: false }); + it('should throw a 401, not authenticated error', async () => { + const error = await getFilesets( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: false } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(401); }); @@ -227,10 +198,14 @@ describe('Dataset Resolver Unit Tests:', function () { it('should return a 500 error', async () => { sinon.stub(Dataset, 'aggregate').throws(); - const result = await getFilesets({}, { input }, { user, req, isAuthenticated: true }); + const result = await getFilesets( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(500) + expect(result.extensions.code).to.be.equal(500); }); }); @@ -245,11 +220,19 @@ describe('Dataset Resolver Unit Tests:', function () { const mockCreatedDataset = { _id: '62d951cb6981a12d136a0a0d', ...mockDataset - } - sinon.stub(Dataset, 'findOne').returns({ _id: '62d951cb6981a12d136a0a0d', filesets: [] }) - sinon.stub(Dataset, 'findOneAndUpdate').callsFake(() => (mockCreatedDataset)) - - const dataset = await createDataset({}, { input }, { user, req, isAuthenticated: true }); + }; + sinon + .stub(Dataset, 'findOne') + .returns({ _id: '62d951cb6981a12d136a0a0d', filesets: [] }); + sinon + .stub(Dataset, 'findOneAndUpdate') + .callsFake(() => mockCreatedDataset); + + const dataset = await createDataset( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: true } + ); expect(dataset).to.have.property('filesets'); }); @@ -257,52 +240,79 @@ describe('Dataset Resolver Unit Tests:', function () { const mockCreatedDataset = { _id: '62d951cb6981a12d136a0a0d', ...mockDataset - } - sinon.stub(Dataset, 'findOne').returns({ _id: '62d951cb6981a12d136a0a0d', filesets: [] }) - sinon.stub(Dataset, 'findOneAndUpdate').callsFake(() => (mockCreatedDataset)) - - const dataset = await createDataset({}, { input: {...input, files: [] } }, { user, req, isAuthenticated: true }); + }; + sinon + .stub(Dataset, 'findOne') + .returns({ _id: '62d951cb6981a12d136a0a0d', filesets: [] }); + sinon + .stub(Dataset, 'findOneAndUpdate') + .callsFake(() => mockCreatedDataset); + + const dataset = await createDataset( + {}, + { input: { ...mockFiles, files: [] } }, + { user, req, isAuthenticated: true } + ); expect(dataset).to.have.property('filesets'); }); - it("should throw a 401, not authenticated error", async () => { - const result = await createDataset({}, { input }, { user, req, isAuthenticated: false }); + it('should throw a 401, not authenticated error', async () => { + const result = await createDataset( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: false } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(401) + expect(result.extensions.code).to.be.equal(401); }); it('should return a 404, not found error', async () => { - sinon.stub(Dataset, 'findOne').returns(null) + sinon.stub(Dataset, 'findOne').returns(null); - const result = await createDataset({}, { input }, { user, req, isAuthenticated: true }); + const result = await createDataset( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(404) + expect(result.extensions.code).to.be.equal(404); }); it('should return a 409, conflict error', async () => { - sinon.stub(Dataset, 'findOne').returns(mockDataset) + sinon.stub(Dataset, 'findOne').returns(mockDataset); - const result = await createDataset({}, { input }, { user, req, isAuthenticated: true }); + const result = await createDataset( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(409) + expect(result.extensions.code).to.be.equal(409); }); it('should throw a 500 error', async () => { - sinon.stub(Dataset, 'findOne').returns({ _id: '62d951cb6981a12d136a0a0d', status: 'WORK IN PROGRESS' }) - sinon.stub(Dataset, 'findOneAndUpdate').throws() + sinon.stub(Dataset, 'findOne').returns({ + _id: '62d951cb6981a12d136a0a0d', + status: 'WORK IN PROGRESS' + }); + sinon.stub(Dataset, 'findOneAndUpdate').throws(); - const result = await createDataset({}, { input }, { user, req, isAuthenticated: true }); + const result = await createDataset( + {}, + { input: mockFiles }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(500) + expect(result.extensions.code).to.be.equal(500); }); it('should return CreatedDataset datatype for createDatasetId(...) mutation', () => { const { createDataset } = graphQlSchema.getMutationType().getFields(); expect(createDataset.type.toString()).to.equal('CreatedDataset!'); }); - }) + }); }); diff --git a/resfulservice/spec/graphql/resolver/material_template.spec.js b/resfulservice/spec/graphql/resolver/material_template.spec.js index 13e2dd6b..e8ea1e99 100644 --- a/resfulservice/spec/graphql/resolver/material_template.spec.js +++ b/resfulservice/spec/graphql/resolver/material_template.spec.js @@ -1,102 +1,60 @@ const chai = require('chai'); const sinon = require('sinon'); -const MaterialTemplate = require('../../../src/models/xlsxCurationList') +const MaterialTemplate = require('../../../src/models/xlsxCurationList'); const graphQlSchema = require('../../../src/graphql'); -const { Mutation: { createXlsxCurationList, updateXlsxCurationList, deleteXlsxCurationList }, Query: { getXlsxCurationList }} = require('../../../src/graphql/resolver'); - +const { + Mutation: { + createXlsxCurationList, + updateXlsxCurationList, + deleteXlsxCurationList + }, + Query: { getXlsxCurationList } +} = require('../../../src/graphql/resolver'); +const { + user, + mockColumnsInput, + mockColumn, + mockDBColumn, + mockConflictError +} = require('../../mocks'); const { expect } = chai; -const user = { - _id: 'ai094oja09aw40-o', - displayName: "test" -} -const mockColumn = { - field: "Flight_width::Uniter", - values: [ - "nm", - "um", - "mm", - "cm", - "m" - ] -} - -const mockColumnsInput = { - columns: [ - { - field: "Flight_width::Units", - values: [ - "nm", - "um", - "mm", - "cm", - "m" - ] - }, - { - field: "Origins", - values: [ - "experiments", - "informatics (data science)", - "simulations", - "theory" - ] - } - ] -} - -const mockDBColumn = { - _id: 'kas2344nlkla', - ...mockColumn, - lean: () => this -} - -const mockConflictError = { - writeErrors: [ - { - err: { - index: 0, - code: 11000, - errmsg: 'E11000 duplicate key error collection: mgi.materialtemplates index: field_1 dup key: { field: "Flight_width::Units" }', - } - }, - { - err: { - index: 1, - code: 11000, - errmsg: 'E11000 duplicate key error collection: mgi.materialtemplates index: field_1 dup key: { field: "Origins" }', - } - } - ] -} describe('Material Template Resolver Unit Tests:', function () { - afterEach(() => sinon.restore()); - const req = { logger: { info: (message) => { }, error: (message) => { } } } + const req = { logger: { info: (message) => {}, error: (message) => {} } }; context('createXlsxCurationList', () => { const input = { ...mockColumnsInput - } + }; it('should have createXlsxCurationList(...) as a Mutation resolver', async function () { - const { createXlsxCurationList } = graphQlSchema.getMutationType().getFields(); + const { createXlsxCurationList } = graphQlSchema + .getMutationType() + .getFields(); expect(createXlsxCurationList.name).to.equal('createXlsxCurationList'); }); it('should create new material colums', async () => { sinon.stub(MaterialTemplate, 'insertMany').returns(true); // sinon.stub(MaterialTemplate.prototype, 'save').callsFake(() => ({...input, _id: 'b39ak9qna'})) - const columns = await createXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const columns = await createXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(columns).to.have.property('columns'); }); it('should return a 401 unauthenticated error', async () => { - - const result = await createXlsxCurationList({}, { input: { } }, { user, req, isAuthenticated: false }); + const result = await createXlsxCurationList( + {}, + { input: {} }, + { user, req, isAuthenticated: false } + ); expect(result).to.have.property('extensions'); expect(result.extensions.code).to.be.equal(401); @@ -104,47 +62,72 @@ describe('Material Template Resolver Unit Tests:', function () { it('should return a 409 conflict error', async () => { sinon.stub(MaterialTemplate, 'insertMany').throws(mockConflictError); - const result = await createXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const result = await createXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); expect(result.extensions.code).to.be.equal(409); }); it('should return MaterialColumns!! datatype for createXlsxCurationList(...) mutation', () => { - const { createXlsxCurationList } = graphQlSchema.getMutationType().getFields(); - expect(createXlsxCurationList.type.toString()).to.equal('MaterialColumns!'); + const { createXlsxCurationList } = graphQlSchema + .getMutationType() + .getFields(); + expect(createXlsxCurationList.type.toString()).to.equal( + 'MaterialColumns!' + ); }); - }) + }); context('updateXlsxCurationList', () => { - const input = { ...mockColumn } - it("should throw a 401, not authenticated error", async () => { - - const error = await updateXlsxCurationList({}, { input }, { user, req, isAuthenticated: false }); + const input = { ...mockColumn }; + it('should throw a 401, not authenticated error', async () => { + const error = await updateXlsxCurationList( + {}, + { 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(MaterialTemplate, 'findOneAndUpdate').returns(null); - const error = await updateXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const error = await updateXlsxCurationList( + {}, + { 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(MaterialTemplate, 'findOneAndUpdate').returns({...mockDBColumn, ...input, user}); + it('should update column if column exists', async () => { + sinon + .stub(MaterialTemplate, 'findOneAndUpdate') + .returns({ ...mockDBColumn, ...input, user }); - const result = await updateXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const result = await updateXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('field'); expect(result).to.have.property('values'); }); - it("should throw a 500, server error", async () => { + it('should throw a 500, server error', async () => { sinon.stub(MaterialTemplate, 'findOneAndUpdate').throws(); - const error = await updateXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const error = await updateXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(500); @@ -152,9 +135,13 @@ describe('Material Template Resolver Unit Tests:', function () { }); context('deleteXlsxCurationList', () => { - const input = { field: mockColumn.field } - it("should throw a 401, not authenticated error", async () => { - const error = await deleteXlsxCurationList({}, { input }, { user, req, isAuthenticated: false }); + const input = { field: mockColumn.field }; + it('should throw a 401, not authenticated error', async () => { + const error = await deleteXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: false } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(401); @@ -162,29 +149,41 @@ describe('Material Template Resolver Unit Tests:', function () { it("should return a 404 error if column doesn't exist", async () => { sinon.stub(MaterialTemplate, 'findOneAndDelete').returns({ - lean: sinon.stub().returns(null), + lean: sinon.stub().returns(null) }); - const error = await deleteXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const error = await deleteXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(404); }); - it("should delete a curation list", async () => { + it('should delete a curation list', async () => { sinon.stub(MaterialTemplate, 'findOneAndDelete').returns({ - lean: sinon.stub().returns(mockDBColumn), + lean: sinon.stub().returns(mockDBColumn) }); - const result = await deleteXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const result = await deleteXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('field'); expect(result).to.have.property('values'); }); - it("should throw a 500, server error", async () => { + it('should throw a 500, server error', async () => { sinon.stub(MaterialTemplate, 'findOneAndDelete').returns({ - lean: sinon.stub().throws(), + lean: sinon.stub().throws() }); - const error = await deleteXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const error = await deleteXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(500); @@ -192,45 +191,60 @@ describe('Material Template Resolver Unit Tests:', function () { }); context('getXlsxCurationList', () => { - const input = { pageNumber: 1, pageSize: 10 } - it("should throw a 401, not authenticated error", async () => { - - const error = await getXlsxCurationList({}, { input }, { user, req, isAuthenticated: false }); + const input = { pageNumber: 1, pageSize: 10 }; + it('should throw a 401, not authenticated error', async () => { + const error = await getXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: false } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(401); }); - it("should return paginated lists of columns", async () => { + it('should return paginated lists of columns', async () => { sinon.stub(MaterialTemplate, 'countDocuments').returns(2); sinon.stub(MaterialTemplate, 'find').returns({ limit: sinon.stub().returnsThis(), skip: sinon.stub().returns(mockColumnsInput.columns) }); - const result = await getXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const result = await getXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('columns'); expect(result.columns).to.be.an('Array'); }); - it("should return paginated lists of columns", async () => { + it('should return paginated lists of columns', async () => { const input = { field: mockColumn.field }; - sinon.stub(MaterialTemplate, 'countDocuments').returns(2) + sinon.stub(MaterialTemplate, 'countDocuments').returns(2); sinon.stub(MaterialTemplate, 'find').returns({ limit: sinon.stub().returnsThis(), skip: sinon.stub().returns(mockColumnsInput.columns) }); - const result = await getXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const result = await getXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(result).to.have.property('columns'); expect(result.columns).to.be.an('Array'); }); - it("should throw a 500, server error", async () => { - sinon.stub(MaterialTemplate, 'countDocuments').returns(2) + it('should throw a 500, server error', async () => { + sinon.stub(MaterialTemplate, 'countDocuments').returns(2); sinon.stub(MaterialTemplate, 'find').throws(); - const error = await getXlsxCurationList({}, { input }, { user, req, isAuthenticated: true }); + const error = await getXlsxCurationList( + {}, + { input }, + { user, req, isAuthenticated: true } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(500); diff --git a/resfulservice/spec/graphql/resolver/pixelated.spec.js b/resfulservice/spec/graphql/resolver/pixelated.spec.js index f5633610..acd7a943 100644 --- a/resfulservice/spec/graphql/resolver/pixelated.spec.js +++ b/resfulservice/spec/graphql/resolver/pixelated.spec.js @@ -1,68 +1,58 @@ const chai = require('chai'); const sinon = require('sinon'); -const PixelData = require('../../../src/models/pixelated') -const graphQlSchema = require('../../../src/graphql'); -const { Query: { pixelData } } = require('../../../src/graphql/resolver'); - +const PixelData = require('../../../src/models/pixelated'); +const { + Query: { pixelData } +} = require('../../../src/graphql/resolver'); +const { mockPixelData, pixelatedDataInput } = require('../../mocks'); const { expect } = chai; describe('PixelData Resolver Unit Tests:', function () { - afterEach(() => sinon.restore()); - this.timeout(10000) + this.timeout(10000); - const input = { - unitCell: 'TEN', - pageNumber: 1, - pageSize: 1 - } - - const req = { logger: { info: (_message) => { }, error: (_message) => { } } } + const req = { logger: { info: (_message) => {}, error: (_message) => {} } }; context('pixelData', () => { it('should return paginated lists of pixelData', async () => { - const mockPixelData = { - _id: 'akdn9wqknd90uaoikn9ahoi4489i', - symmetry: 'C4v', - unit_cell_x_pixels: '10', - unit_cell_y_pixels: '10', - geometry_condensed: '000000000001001', - geometry_full: '1010000101000000000010000000010000000000000000000000000000000000000000100000000100000000001010000101', - condition: 'Plane Strain', - C11: '2963290579', - C12: '1459531181', - C22: '2963290579', - skip: () => ({_id: 'akdn9wqkn', ...input }), - lean: () => ({_id: 'akdn9wqkn', ...input }), - limit: () => ({_id: 'akdn9wqkn', ...input }) - } sinon.stub(PixelData, 'countDocuments').returns(1); sinon.stub(PixelData, 'find').returns(mockPixelData); sinon.stub(mockPixelData, 'skip').returnsThis(); sinon.stub(mockPixelData, 'limit').returnsThis(); sinon.stub(mockPixelData, 'lean').returns([mockPixelData]); - const pixelatedData = await pixelData({}, { input }, { req }); + const pixelatedData = await pixelData( + {}, + { input: pixelatedDataInput }, + { req } + ); expect(pixelatedData).to.have.property('data'); expect(pixelatedData.totalItems).to.equal(1); }); - it("should throw a 400, input error", async () => { - - const error = await pixelData({}, { input: { unitCell: "BOTH" } }, { req }); + it('should throw a 400, input error', async () => { + const error = await pixelData( + {}, + { input: { unitCell: 'BOTH' } }, + { req } + ); expect(error).to.have.property('extensions'); expect(error.extensions.code).to.be.equal(400); }); it('should return a 500 error', async () => { sinon.stub(PixelData, 'countDocuments').returns(1); - sinon.stub(PixelData, 'find').throws() + sinon.stub(PixelData, 'find').throws(); - const result = await pixelData({}, { input }, { req, isAuthenticated: true }); + const result = await pixelData( + {}, + { input: pixelatedDataInput }, + { req, isAuthenticated: true } + ); expect(result).to.have.property('extensions'); - expect(result.extensions.code).to.be.equal(500) + expect(result.extensions.code).to.be.equal(500); }); - }) -}); + }); +}); diff --git a/resfulservice/spec/graphql/resolver/xml.spec.js b/resfulservice/spec/graphql/resolver/xml.spec.js index 98112d6b..422fdd76 100644 --- a/resfulservice/spec/graphql/resolver/xml.spec.js +++ b/resfulservice/spec/graphql/resolver/xml.spec.js @@ -7,6 +7,7 @@ const { Query: { xmlFinder, xmlViewer } } = require('../../../src/graphql/resolver'); const CuratedSamples = require('../../../src/models/curatedSamples'); +const { mockDBXmlDataList, mockDBXmlData } = require('../../mocks'); const { expect } = chai; @@ -18,25 +19,6 @@ const mockXmlData = { entityState: 'EditedValid' }; -const mockXmlDataList = [ - { - id: '6622848a808bdbee354f96d3', - title: 'L311_S10_Lou_2009.xml', - status: 'Not Approved', - isNewCuration: false, - sequence: 311, - user: '65b8ec85c3d3b2ed82fe4029' - }, - { - id: '65cf719860df704a1ca74428', - title: 'E0_S1_Uthdev_2003.xml', - status: 'Approved', - isNewCuration: true, - sequence: null, - user: '65b8ec85c3d3b2ed82fe4029' - } -]; - describe('XmlData Resolver Unit Tests:', function () { afterEach(() => sinon.restore()); @@ -58,33 +40,35 @@ describe('XmlData Resolver Unit Tests:', function () { sinon.stub(CuratedSamples, 'countDocuments').returns(1); sinon .stub(XmlData, 'aggregate') - .returns([{ count: mockXmlDataList.length, xmlData: mockXmlDataList }]); + .returns([ + { count: mockDBXmlDataList.length, xmlData: mockDBXmlDataList } + ]); const result = await xmlFinder({}, { input }, { req }); expect(result).to.have.property('xmlData'); expect(result.xmlData).to.be.an('Array'); - expect(result.xmlData[0]).to.have.property('id', mockXmlDataList[0].id); + expect(result.xmlData[0]).to.have.property('id', mockDBXmlDataList[0].id); expect(result.xmlData[0]).to.have.property( 'title', - mockXmlDataList[0].title + mockDBXmlDataList[0].title ); expect(result.xmlData[0]).to.have.property( 'status', - mockXmlDataList[0].status + mockDBXmlDataList[0].status ); expect(result.xmlData[0]).to.have.property( 'isNewCuration', - mockXmlDataList[0].isNewCuration + mockDBXmlDataList[0].isNewCuration ); expect(result.xmlData[0]).to.have.property( 'sequence', - mockXmlDataList[0].sequence + mockDBXmlDataList[0].sequence ); expect(result.xmlData[0]).to.have.property( 'user', - mockXmlDataList[0].user + mockDBXmlDataList[0].user ); }); @@ -94,33 +78,35 @@ describe('XmlData Resolver Unit Tests:', function () { sinon .stub(XmlData, 'aggregate') - .returns([{ count: mockXmlDataList.length, xmlData: mockXmlDataList }]); + .returns([ + { count: mockDBXmlDataList.length, xmlData: mockDBXmlDataList } + ]); const result = await xmlFinder({}, { input }, { req }); expect(result).to.have.property('xmlData'); expect(result.xmlData).to.be.an('Array'); - expect(result.xmlData[1]).to.have.property('id', mockXmlDataList[1].id); + expect(result.xmlData[1]).to.have.property('id', mockDBXmlDataList[1].id); expect(result.xmlData[1]).to.have.property( 'title', - mockXmlDataList[1].title + mockDBXmlDataList[1].title ); expect(result.xmlData[1]).to.have.property( 'status', - mockXmlDataList[1].status + mockDBXmlDataList[1].status ); expect(result.xmlData[1]).to.have.property( 'isNewCuration', - mockXmlDataList[1].isNewCuration + mockDBXmlDataList[1].isNewCuration ); expect(result.xmlData[1]).to.have.property( 'sequence', - mockXmlDataList[1].sequence + mockDBXmlDataList[1].sequence ); expect(result.xmlData[1]).to.have.property( 'user', - mockXmlDataList[1].user + mockDBXmlDataList[1].user ); }); @@ -148,7 +134,7 @@ describe('XmlData Resolver Unit Tests:', function () { }); it('should return an xmldata', async () => { - sinon.stub(XmlData, 'findOne').returns(mockXmlData); + sinon.stub(XmlData, 'findOne').returns(mockDBXmlData); const result = await xmlViewer({}, { input }, { req }); @@ -159,7 +145,9 @@ describe('XmlData Resolver Unit Tests:', function () { it('should return a curated sample data', async () => { sinon.stub(CuratedSamples, 'findOne').returns(fetchedCuratedXlsxObject); - sinon.stub(XlsxFileManager, 'xmlGenerator').returns(mockXmlData.xml_str); + sinon + .stub(XlsxFileManager, 'xmlGenerator') + .returns(mockDBXmlData.xml_str); const result = await xmlViewer( {}, { input: { ...input, isNewCuration: true } }, diff --git a/resfulservice/spec/mocks/graphqlMock.js b/resfulservice/spec/mocks/graphqlMock.js new file mode 100644 index 00000000..b6a443ed --- /dev/null +++ b/resfulservice/spec/mocks/graphqlMock.js @@ -0,0 +1,267 @@ +const sinon = require('sinon'); + +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' + } +]; + +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 mockUserContact = { + _id: 'akdn9wqkn', + fullName: 'test user', + email: 'test@example.com', + purpose: 'QUESTION', + message: 'test message', + lean: () => this +}; + +const mockUpdatedContact = { + ...mockContact, + resolved: true, + response: 'Thanks for reaching out. We are working on it' +}; + +const user = { + _id: '62dab1b76db8739c8330611d', + alias: 'testalias', + givenName: 'test', + surName: 'test user', + displayName: 'tester', + userid: '62dab1b76db8739c8330611d', + email: 'test@example.com', + roles: 'member' +}; + +const mockDataset = { + _id: '62f11b1328eedaab012d127c', + datasetId: '62f11b1328eedaab012d127c', + userid: '62f119fb28eedaab012d1262', + filesets: [ + { + fileset: 'E109_S2_Huang_2016', + files: [ + { + type: 'blob', + id: '5b51f112e74a1d4cdbad6a1d', + metadata: { + filename: '4.tif', + contentType: 'image/tiff' + } + }, + { + type: 'blob', + id: '5b51f137e74a1d4cdbad6a3a', + metadata: { + filename: '5.tif', + contentType: 'image/tiff' + } + } + ] + } + ], + skip: sinon.stub().returnsThis(), + limit: sinon.stub().returnsThis(), + lean: sinon.stub().returnsThis() +}; + +const mockFiles = { + doi: 'unpublished/doi-tMbKM2ba5aNwo2ZKPVucBS', + datasetId: '62fce36374da548513a38a9b', + files: [ + { + fieldname: 'uploadfile', + originalname: 'Hopetoun_falls.jpg', + encoding: '7bit', + mimetype: 'image/jpeg', + destination: 'mm_files', + filename: + 'comparative_aphid_agathe-2022-08-18T10:00:40.910Z-Hopetoun_falls.jpg', + path: 'mm_files/comparative_aphid_agathe-2022-08-18T10:00:40.910Z-Hopetoun_falls.jpg', + size: 2954043 + }, + { + fieldname: 'uploadfile', + originalname: 'flowers-276014__340.jpg', + encoding: '7bit', + mimetype: 'image/jpeg', + destination: 'mm_files', + filename: + 'comparative_aphid_agathe-2022-08-18T10:00:41.018Z-flowers-276014__340.jpg', + path: 'mm_files/comparative_aphid_agathe-2022-08-18T10:00:41.018Z-flowers-276014__340.jpg', + size: 56575 + } + ] +}; + +const mockColumn = { + field: 'Flight_width::Uniter', + values: ['nm', 'um', 'mm', 'cm', 'm'] +}; + +const mockColumnsInput = { + columns: [ + { + field: 'Flight_width::Units', + values: ['nm', 'um', 'mm', 'cm', 'm'] + }, + { + field: 'Origins', + values: [ + 'experiments', + 'informatics (data science)', + 'simulations', + 'theory' + ] + } + ] +}; + +const mockDBColumn = { + _id: 'kas2344nlkla', + ...mockColumn, + lean: () => this +}; + +const mockConflictError = { + writeErrors: [ + { + err: { + index: 0, + code: 11000, + errmsg: + 'E11000 duplicate key error collection: mgi.materialtemplates index: field_1 dup key: { field: "Flight_width::Units" }' + } + }, + { + err: { + index: 1, + code: 11000, + errmsg: + 'E11000 duplicate key error collection: mgi.materialtemplates index: field_1 dup key: { field: "Origins" }' + } + } + ] +}; + +const pixelatedDataInput = { + unitCell: 'TEN', + pageNumber: 1, + pageSize: 1 +}; + +const mockPixelData = { + _id: 'akdn9wqknd90uaoikn9ahoi4489i', + symmetry: 'C4v', + unit_cell_x_pixels: '10', + unit_cell_y_pixels: '10', + geometry_condensed: '000000000001001', + geometry_full: + '1010000101000000000010000000010000000000000000000000000000000000000000100000000100000000001010000101', + condition: 'Plane Strain', + C11: '2963290579', + C12: '1459531181', + C22: '2963290579', + skip: () => ({ _id: 'akdn9wqkn', ...pixelatedDataInput }), + lean: () => ({ _id: 'akdn9wqkn', ...pixelatedDataInput }), + limit: () => ({ _id: 'akdn9wqkn', ...pixelatedDataInput }) +}; + +const mockDBXmlData = { + _id: '64394c8032bc6325505af6f9', + title: 'L183_53_Portschke_2003.xml', + xml_str: + ' Empire BurlesqueBob Dylan USA Columbia 10.90 1985 ', + entityState: 'EditedValid' +}; + +const mockDBXmlDataList = [ + { + id: '6622848a808bdbee354f96d3', + title: 'L311_S10_Lou_2009.xml', + status: 'Not Approved', + isNewCuration: false, + sequence: 311, + user: '65b8ec85c3d3b2ed82fe4029' + }, + { + id: '65cf719860df704a1ca74428', + title: 'E0_S1_Uthdev_2003.xml', + status: 'Approved', + isNewCuration: true, + sequence: null, + user: '65b8ec85c3d3b2ed82fe4029' + } +]; + +module.exports = { + mockComment, + mockCommentInput, + mockDBComment, + mockCommentList, + mockContact, + mockUserContact, + mockUpdatedContact, + mockDataset, + mockFiles, + mockColumn, + mockColumnsInput, + mockDBColumn, + mockConflictError, + mockPixelData, + pixelatedDataInput, + mockDBXmlDataList, + mockDBXmlData, + user +}; diff --git a/resfulservice/spec/mocks/index.js b/resfulservice/spec/mocks/index.js index c5e2b1d6..0beacf77 100644 --- a/resfulservice/spec/mocks/index.js +++ b/resfulservice/spec/mocks/index.js @@ -2,6 +2,7 @@ const curation = require('./curationMock'); const user = require('./userMock'); const files = require('./fileMock'); const tasks = require('./taskMock'); +const graphql = require('./graphqlMock'); // It is re-useable across all tests files const next = function (fn) { @@ -13,5 +14,6 @@ module.exports = { ...user, ...files, ...tasks, + ...graphql, next };