How to use testProject method in Puppeteer

Best JavaScript code snippet using puppeteer

projects.js

Source:projects.js Github

copy

Full Screen

1const test = require('unit.js');2const helper = require('../helper');3const config = require('../../config');4const db = require('../../helpers/db');5describe('routes/projects.js', function () {6 const email = 'test@controlio.co';7 const managerEmail = 'manager@controlio.co';8 const secondManagerEmail = 'secondmanager@controlio.co';9 const demoEmail = 'awesome@controlio.co';10 const testOwnerEmail = 'testowner@controlio.co';11 const clientEmails = [12 'client1@controlio.co',13 'client2@controlio.co',14 'client3@controlio.co',15 ];16 let user;17 let managerObject;18 let secondManagerObject;19 let clientObjects;20 let testProject;21 let testProjectCannotEdit;22 let testOwner;23 before(function (done) {24 helper.closeConnectDrop()25 .then(() => helper.addUserWithJWT({ email, plan: 3 }))26 .then((dbuser) => {27 user = dbuser;28 })29 .then(() => helper.addUserWithJWT({ email: demoEmail, isDemo: true }))30 .then(() => done())31 .catch(done);32 });33 after(function (done) {34 helper.dropClose()35 .then(done)36 .catch(done);37 });38 context('POST /projects', function () {39 it('creates a project as a client', function (done) {40 helper.request41 .post('/projects')42 .set('apiKey', config.apiKey)43 .set('token', user.token)44 .send({45 title: 'Test client',46 type: 'client',47 description: 'Test project description',48 initialStatus: 'Test initial status',49 managerEmail,50 progressEnabled: true,51 image: 'key/to/test/image.png',52 })53 .expect(200, (err, res) => {54 if (err) return done(err);55 try {56 const json = JSON.parse(res.text);57 test58 .object(json)59 .hasProperty('title', 'Test client')60 .hasProperty('description', 'Test project description')61 .hasProperty('isFinished', false)62 .hasProperty('progressEnabled', true)63 .hasProperty('image', 'key/to/test/image.png')64 .hasNotProperty('owner')65 .array(json.posts)66 .hasLength(1)67 .object(json.posts[0])68 .hasProperty('text', 'Test initial status')69 .hasProperty('isEdited', false)70 .hasProperty('type', 'status')71 .array(json.posts[0].attachments)72 .hasLength(0)73 .array(json.invites)74 .hasLength(1)75 .array(json.clients)76 .hasLength(1)77 .object(json.clients[0])78 .hasProperty('email', email)79 .array(json.managers)80 .hasLength(0)81 .object(json.lastPost)82 .hasProperty('text', 'Test initial status')83 .hasProperty('isEdited', false)84 .hasProperty('type', 'status')85 .array(json.posts[0].attachments)86 .hasLength(0)87 .object(json.lastStatus)88 .hasProperty('text', 'Test initial status')89 .hasProperty('isEdited', false)90 .hasProperty('type', 'status')91 .array(json.posts[0].attachments)92 .hasLength(0);93 done();94 } catch (error) {95 done(error);96 }97 });98 });99 it('invites manager after creating a project as a client', function (done) {100 db.findUser({ email: managerEmail })101 .then((manager) => {102 test.object(manager.toObject())103 .hasProperty('email', managerEmail)104 .array(manager.toObject().invites)105 .hasLength(1);106 done();107 })108 .catch(done);109 });110 it('creates a project without image, description, client emails, progressEnabled and initial status as a client', function (done) {111 helper.request112 .post('/projects')113 .set('apiKey', config.apiKey)114 .set('token', user.token)115 .send({116 title: 'Test client almost empty',117 type: 'client',118 managerEmail,119 })120 .expect(200, (err, res) => {121 if (err) return done(err);122 try {123 const json = JSON.parse(res.text);124 test125 .object(json)126 .hasProperty('title', 'Test client almost empty')127 .hasNotProperty('description')128 .hasProperty('isFinished', false)129 .hasProperty('progressEnabled', false)130 .hasNotProperty('image')131 .hasNotProperty('owner')132 .hasNotProperty('lastPost')133 .hasNotProperty('lastStatus')134 .array(json.posts)135 .hasLength(0)136 .array(json.invites)137 .hasLength(1)138 .array(json.clients)139 .hasLength(1)140 .object(json.clients[0])141 .hasProperty('email', email)142 .array(json.managers)143 .hasLength(0);144 done();145 } catch (error) {146 done(error);147 }148 });149 });150 it('creates another project without image, description, client emails and initial status as a client', function (done) {151 helper.request152 .post('/projects')153 .set('apiKey', config.apiKey)154 .set('token', user.token)155 .send({156 title: 'Test owner can reject',157 type: 'client',158 managerEmail: testOwnerEmail,159 })160 .expect(200, (err, res) => {161 if (err) return done(err);162 try {163 const json = JSON.parse(res.text);164 test.object(json)165 .hasProperty('title', 'Test owner can reject');166 done();167 } catch (error) {168 done(error);169 }170 });171 });172 it('creates third project without image, description, client emails and initial status as a client', function (done) {173 helper.request174 .post('/projects')175 .set('apiKey', config.apiKey)176 .set('token', user.token)177 .send({178 title: 'Test owner can reject 2',179 type: 'client',180 managerEmail: testOwnerEmail,181 })182 .expect(200, (err, res) => {183 if (err) return done(err);184 try {185 const json = JSON.parse(res.text);186 test.object(json)187 .hasProperty('title', 'Test owner can reject 2');188 done();189 } catch (error) {190 done(error);191 }192 });193 });194 it('creates third project as client', function (done) {195 helper.request196 .post('/projects')197 .set('apiKey', config.apiKey)198 .set('token', user.token)199 .send({200 title: 'Test client third',201 type: 'client',202 managerEmail,203 })204 .expect(200, (err, res) => {205 if (err) return done(err);206 try {207 const json = JSON.parse(res.text);208 test209 .object(json)210 .hasProperty('title', 'Test client third')211 .hasNotProperty('description')212 .hasProperty('isFinished', false)213 .hasNotProperty('image')214 .hasNotProperty('owner')215 .hasNotProperty('lastPost')216 .hasNotProperty('lastStatus')217 .array(json.posts)218 .hasLength(0)219 .array(json.invites)220 .hasLength(1)221 .array(json.clients)222 .hasLength(1)223 .object(json.clients[0])224 .hasProperty('email', email)225 .array(json.managers)226 .hasLength(0);227 done();228 } catch (error) {229 done(error);230 }231 });232 });233 it('does not create manager object twice', function (done) {234 db.findUsers({ email: managerEmail })235 .then((users) => {236 test.array(users)237 .hasLength(1);238 done();239 })240 .catch(done);241 });242 it('returns error creating a project with malformed manager email as client', function (done) {243 helper.request244 .post('/projects')245 .set('apiKey', config.apiKey)246 .set('token', user.token)247 .send({248 type: 'client',249 title: 'SHould fail',250 managerEmail: '123',251 })252 .expect(400, (err, res) => {253 if (err) return done(err);254 try {255 const json = JSON.parse(res.text);256 test.object(json)257 .hasProperty('type', 'VALIDATION_ERROR');258 done();259 } catch (error) {260 done(error);261 }262 });263 });264 it('returns error creating a project with malformed progressEnabled flag as client', function (done) {265 helper.request266 .post('/projects')267 .set('apiKey', config.apiKey)268 .set('token', user.token)269 .send({270 type: 'client',271 title: 'Should fail',272 progressEnabled: '90qwe',273 managerEmail,274 })275 .expect(400, (err, res) => {276 if (err) return done(err);277 try {278 const json = JSON.parse(res.text);279 test.object(json)280 .hasProperty('type', 'VALIDATION_ERROR');281 done();282 } catch (error) {283 done(error);284 }285 });286 });287 it('returns error creating a project without title', function (done) {288 helper.request289 .post('/projects')290 .set('apiKey', config.apiKey)291 .set('token', user.token)292 .send({293 type: 'client',294 managerEmail,295 })296 .expect(400, (err, res) => {297 if (err) return done(err);298 try {299 const json = JSON.parse(res.text);300 test.object(json)301 .hasProperty('type', 'VALIDATION_ERROR');302 done();303 } catch (error) {304 done(error);305 }306 });307 });308 it('returns error creating a project without type', function (done) {309 helper.request310 .post('/projects')311 .set('apiKey', config.apiKey)312 .set('token', user.token)313 .send({314 title: 'Test client without type',315 managerEmail,316 })317 .expect(400, (err, res) => {318 if (err) return done(err);319 try {320 const json = JSON.parse(res.text);321 test.object(json)322 .hasProperty('type', 'VALIDATION_ERROR');323 done();324 } catch (error) {325 done(error);326 }327 });328 });329 it('returns error creating a project without managerEmail as a client', function (done) {330 helper.request331 .post('/projects')332 .set('apiKey', config.apiKey)333 .set('token', user.token)334 .send({335 title: 'Test client without manager email',336 type: 'client',337 })338 .expect(400, (err, res) => {339 if (err) return done(err);340 try {341 const json = JSON.parse(res.text);342 test.object(json)343 .hasProperty('type', 'VALIDATION_ERROR');344 done();345 } catch (error) {346 done(error);347 }348 });349 });350 it('returns error creating a project with manager email too long', function (done) {351 const stub = '1234567890';352 let manager = stub;353 for (let i = 0; i < 11; i += 1) {354 manager += stub;355 }356 helper.request357 .post('/projects')358 .set('apiKey', config.apiKey)359 .set('token', user.token)360 .send({361 title: 'Manager email that is too long',362 type: 'client',363 managerEmail: `${manager}@controlio.co`,364 })365 .expect(400, (err, res) => {366 if (err) return done(err);367 try {368 const json = JSON.parse(res.text);369 test.object(json)370 .hasProperty('type', 'VALIDATION_ERROR');371 done();372 } catch (error) {373 done(error);374 }375 });376 });377 it('returns error creating a project as client with self as manager', function (done) {378 helper.request379 .post('/projects')380 .set('apiKey', config.apiKey)381 .set('token', user.token)382 .send({383 title: 'Self as manager',384 type: 'client',385 managerEmail: email,386 })387 .expect(400, (err, res) => {388 if (err) return done(err);389 try {390 const json = JSON.parse(res.text);391 test.object(json)392 .hasProperty('type', 'ADD_SELF_AS_MANAGER_ERROR');393 done();394 } catch (error) {395 done(error);396 }397 });398 });399 it('returns error creating a project as client with demo as manager', function (done) {400 helper.request401 .post('/projects')402 .set('apiKey', config.apiKey)403 .set('token', user.token)404 .send({405 title: 'Demo as manager',406 type: 'client',407 managerEmail: demoEmail,408 })409 .expect(403, (err, res) => {410 if (err) return done(err);411 try {412 const json = JSON.parse(res.text);413 test.object(json)414 .hasProperty('type', 'ADD_DEMO_AS_MANAGER_ERROR');415 done();416 } catch (error) {417 done(error);418 }419 });420 });421 it('returns error creating a project with strange type', function (done) {422 helper.request423 .post('/projects')424 .set('apiKey', config.apiKey)425 .set('token', user.token)426 .send({427 title: 'Test client without manager email',428 type: 'strange',429 managerEmail,430 })431 .expect(400, (err, res) => {432 if (err) return done(err);433 try {434 const json = JSON.parse(res.text);435 test.object(json)436 .hasProperty('type', 'VALIDATION_ERROR');437 done();438 } catch (error) {439 done(error);440 }441 });442 });443 it('returns error creating a project with title too long', function (done) {444 const stub = '1234567890';445 let title = stub;446 for (let i = 0; i < 30; i += 1) {447 title += stub;448 }449 helper.request450 .post('/projects')451 .set('apiKey', config.apiKey)452 .set('token', user.token)453 .send({454 title,455 type: 'client',456 managerEmail,457 })458 .expect(400, (err, res) => {459 if (err) return done(err);460 try {461 const json = JSON.parse(res.text);462 test.object(json)463 .hasProperty('type', 'VALIDATION_ERROR');464 done();465 } catch (error) {466 done(error);467 }468 });469 });470 it('returns error creating a project with description too long', function (done) {471 const stub = '1234567890';472 let description = stub;473 for (let i = 0; i < 101; i += 1) {474 description += stub;475 }476 helper.request477 .post('/projects')478 .set('apiKey', config.apiKey)479 .set('token', user.token)480 .send({481 title: 'description that is too long',482 description,483 type: 'client',484 managerEmail,485 })486 .expect(400, (err, res) => {487 if (err) return done(err);488 try {489 const json = JSON.parse(res.text);490 test.object(json)491 .hasProperty('type', 'VALIDATION_ERROR');492 done();493 } catch (error) {494 done(error);495 }496 });497 });498 it('returns error creating a project with initial status too long', function (done) {499 const stub = '1234567890';500 let initialStatus = stub;501 for (let i = 0; i < 30; i += 1) {502 initialStatus += stub;503 }504 helper.request505 .post('/projects')506 .set('apiKey', config.apiKey)507 .set('token', user.token)508 .send({509 title: 'Initial status that is too long',510 initialStatus,511 type: 'client',512 managerEmail,513 })514 .expect(400, (err, res) => {515 if (err) return done(err);516 try {517 const json = JSON.parse(res.text);518 test.object(json)519 .hasProperty('type', 'VALIDATION_ERROR');520 done();521 } catch (error) {522 done(error);523 }524 });525 });526 it('creates a project as a manager', function (done) {527 helper.request528 .post('/projects')529 .set('apiKey', config.apiKey)530 .set('token', user.token)531 .send({532 title: 'Test manager',533 type: 'manager',534 description: 'Test project description for manager',535 initialStatus: 'Test initial status for manager',536 image: 'key/to/test/image_for_manager.png',537 progressEnabled: true,538 clientEmails,539 })540 .expect(200, (err, res) => {541 if (err) return done(err);542 try {543 const json = JSON.parse(res.text);544 test545 .object(json)546 .hasProperty('title', 'Test manager')547 .hasProperty('description', 'Test project description for manager')548 .hasProperty('isFinished', false)549 .hasProperty('progressEnabled', true)550 .hasProperty('image', 'key/to/test/image_for_manager.png')551 .hasProperty('owner')552 .array(json.posts)553 .hasLength(1)554 .object(json.posts[0])555 .hasProperty('text', 'Test initial status for manager')556 .hasProperty('isEdited', false)557 .hasProperty('type', 'status')558 .array(json.posts[0].attachments)559 .hasLength(0)560 .array(json.invites)561 .hasLength(3)562 .array(json.clients)563 .hasLength(0)564 .array(json.managers)565 .hasLength(0)566 .object(json.lastPost)567 .hasProperty('text', 'Test initial status for manager')568 .hasProperty('isEdited', false)569 .hasProperty('type', 'status')570 .array(json.posts[0].attachments)571 .hasLength(0)572 .object(json.lastStatus)573 .hasProperty('text', 'Test initial status for manager')574 .hasProperty('isEdited', false)575 .hasProperty('type', 'status')576 .array(json.posts[0].attachments)577 .hasLength(0);578 done();579 } catch (error) {580 done(error);581 }582 });583 });584 it('invites clients after creating a project as a manager', function (done) {585 Promise.reduce(clientEmails, (array, clientEmail) =>586 db.findUser({ email: clientEmail })587 .then((client) => {588 array.push(client);589 return array;590 }), [])591 .then((clients) => {592 clients.forEach((client, index) => {593 test.object(client.toObject())594 .hasProperty('email', clientEmails[index])595 .array(client.toObject().invites)596 .hasLength(1);597 });598 done();599 })600 .catch(done);601 });602 it('creates a project without image, description, manager email, progressEnabled and initial status as a manager', function (done) {603 helper.request604 .post('/projects')605 .set('apiKey', config.apiKey)606 .set('token', user.token)607 .send({608 title: 'Test manager almost empty',609 type: 'manager',610 clientEmails,611 })612 .expect(200, (err, res) => {613 if (err) return done(err);614 try {615 const json = JSON.parse(res.text);616 test617 .object(json)618 .hasProperty('title', 'Test manager almost empty')619 .hasNotProperty('description')620 .hasProperty('isFinished', false)621 .hasNotProperty('image')622 .hasProperty('owner')623 .hasNotProperty('lastPost')624 .hasNotProperty('lastStatus')625 .hasProperty('progressEnabled', false)626 .array(json.posts)627 .hasLength(0)628 .array(json.invites)629 .hasLength(3)630 .array(json.clients)631 .hasLength(0)632 .array(json.managers)633 .hasLength(0);634 done();635 } catch (error) {636 done(error);637 }638 });639 });640 it('does not create client objects twice', function (done) {641 Promise.reduce(clientEmails, (array, clientEmail) =>642 db.findUser({ email: clientEmail })643 .then((client) => {644 array.push(client);645 return array;646 }), [])647 .then((clients) => {648 test.array(clients)649 .hasLength(3);650 done();651 })652 .catch(done);653 });654 it('returns error creating a project with malformed client email as manager', function (done) {655 helper.request656 .post('/projects')657 .set('apiKey', config.apiKey)658 .set('token', user.token)659 .send({660 title: 'Should fail',661 type: 'manager',662 clientEmails: ['123'],663 })664 .expect(400, (err, res) => {665 if (err) return done(err);666 try {667 const json = JSON.parse(res.text);668 test.object(json)669 .hasProperty('type', 'VALIDATION_ERROR');670 done();671 } catch (error) {672 done(error);673 }674 });675 });676 it('returns error creating a project with malformed progressEnabled flag as manager', function (done) {677 helper.request678 .post('/projects')679 .set('apiKey', config.apiKey)680 .set('token', user.token)681 .send({682 type: 'client',683 title: 'Should fail',684 progressEnabled: '90qwe',685 clientEmails,686 })687 .expect(400, (err, res) => {688 if (err) return done(err);689 try {690 const json = JSON.parse(res.text);691 test.object(json)692 .hasProperty('type', 'VALIDATION_ERROR');693 done();694 } catch (error) {695 done(error);696 }697 });698 });699 it('returns error creating a project without client emails as a manager', function (done) {700 helper.request701 .post('/projects')702 .set('apiKey', config.apiKey)703 .set('token', user.token)704 .send({705 title: 'Test manager without client emails',706 type: 'manager',707 })708 .expect(400, (err, res) => {709 if (err) return done(err);710 try {711 const json = JSON.parse(res.text);712 test.object(json)713 .hasProperty('type', 'VALIDATION_ERROR');714 done();715 } catch (error) {716 done(error);717 }718 });719 });720 it('returns error creating a project with clients emails too long', function (done) {721 const stub = '1234567890';722 let client = stub;723 for (let i = 0; i < 11; i += 1) {724 client += stub;725 }726 helper.request727 .post('/projects')728 .set('apiKey', config.apiKey)729 .set('token', user.token)730 .send({731 title: 'Client emails that are too long',732 type: 'manager',733 clientEmails: [`${client}@controlio.co`],734 })735 .expect(400, (err, res) => {736 if (err) return done(err);737 try {738 const json = JSON.parse(res.text);739 test.object(json)740 .hasProperty('type', 'VALIDATION_ERROR');741 done();742 } catch (error) {743 done(error);744 }745 });746 });747 it('returns error creating a project as client with self as client', function (done) {748 helper.request749 .post('/projects')750 .set('apiKey', config.apiKey)751 .set('token', user.token)752 .send({753 title: 'Self as client',754 type: 'manager',755 clientEmails: [email],756 })757 .expect(400, (err, res) => {758 if (err) return done(err);759 try {760 const json = JSON.parse(res.text);761 test.object(json)762 .hasProperty('type', 'ADD_SELF_AS_CLIENT_ERROR');763 done();764 } catch (error) {765 done(error);766 }767 });768 });769 it('returns error creating a project as client with demo as client', function (done) {770 helper.request771 .post('/projects')772 .set('apiKey', config.apiKey)773 .set('token', user.token)774 .send({775 title: 'Demo as client',776 type: 'manager',777 clientEmails: [demoEmail],778 })779 .expect(403, (err, res) => {780 if (err) return done(err);781 try {782 const json = JSON.parse(res.text);783 test.object(json)784 .hasProperty('type', 'ADD_DEMO_AS_CLIENT_ERROR');785 done();786 } catch (error) {787 done(error);788 }789 });790 });791 });792 context('POST projects/invite', function () {793 it('grabs manager object and client objects, has correct number of invites on each', function (done) {794 Promise.reduce(clientEmails.concat(managerEmail), (array, inemail) =>795 db.findUser({ email: inemail })796 .then(helper.generateJWT)797 .then(helper.maximizePlan)798 .then((dbuser) => {799 array.push(dbuser);800 return array;801 }), [])802 .then((users) => {803 managerObject = users[3];804 test.object(managerObject.toObject())805 .hasProperty('invites')806 .array(managerObject.toObject().invites)807 .hasLength(3);808 clientObjects = users.slice(0, 3);809 clientObjects.forEach((clientObject) => {810 test.object(clientObject.toObject())811 .hasProperty('invites')812 .array(clientObject.toObject().invites)813 .hasLength(2);814 });815 done();816 })817 .catch(done);818 });819 it('returns an error when not providing invite id on accept invite', function (done) {820 helper.request821 .post('/projects/invite')822 .set('apiKey', config.apiKey)823 .set('token', managerObject.token)824 .send({825 accept: true,826 })827 .expect(400, (err, res) => {828 if (err) return done(err);829 try {830 const json = JSON.parse(res.text);831 test.object(json)832 .hasProperty('type', 'VALIDATION_ERROR');833 done();834 } catch (error) {835 done(error);836 }837 });838 });839 it('returns an error when not providing accept value on accept invite', function (done) {840 helper.request841 .post('/projects/invite')842 .set('apiKey', config.apiKey)843 .set('token', managerObject.token)844 .send({845 inviteid: String(managerObject.invites[1]),846 })847 .expect(400, (err, res) => {848 if (err) return done(err);849 try {850 const json = JSON.parse(res.text);851 test.object(json)852 .hasProperty('type', 'VALIDATION_ERROR');853 done();854 } catch (error) {855 done(error);856 }857 });858 });859 it('returns an error when providing non existing invite id on accept invite', function (done) {860 helper.request861 .post('/projects/invite')862 .set('apiKey', config.apiKey)863 .set('token', managerObject.token)864 .send({865 inviteid: '58e73c820a9f165ffc06c1cf',866 accept: true,867 })868 .expect(400, (err, res) => {869 if (err) return done(err);870 try {871 const json = JSON.parse(res.text);872 test.object(json)873 .hasProperty('type', 'INVITE_NOT_FOUND_ERROR');874 done();875 } catch (error) {876 done(error);877 }878 });879 });880 it('returns an error when providing non existing invite id on reject invite', function (done) {881 helper.request882 .post('/projects/invite')883 .set('apiKey', config.apiKey)884 .set('token', managerObject.token)885 .send({886 inviteid: '58e73c820a9f165ffc06c1cf',887 accept: false,888 })889 .expect(400, (err, res) => {890 if (err) return done(err);891 try {892 const json = JSON.parse(res.text);893 test.object(json)894 .hasProperty('type', 'INVITE_NOT_FOUND_ERROR');895 done();896 } catch (error) {897 done(error);898 }899 });900 });901 it('correctly accepts invite for owner', function (done) {902 helper.request903 .post('/projects/invite')904 .set('apiKey', config.apiKey)905 .set('token', managerObject.token)906 .send({907 inviteid: String(managerObject.invites[1]),908 accept: true,909 })910 .expect(200, (err, res) => {911 if (err) return done(err);912 try {913 const json = JSON.parse(res.text);914 test.object(json)915 .hasProperty('success', true);916 done();917 } catch (error) {918 done(error);919 }920 });921 });922 it('removes invite from owner afterwards and adds project to owner', function (done) {923 db.findUser({ email: managerEmail })924 .select('+token')925 .then((object) => {926 managerObject = object;927 const objectifiedManager = managerObject.toObject();928 test.object(objectifiedManager)929 .array(objectifiedManager.invites)930 .hasLength(2)931 .array(objectifiedManager.projects)932 .hasLength(1);933 done();934 })935 .catch(done);936 });937 it('correctly rejects invite for owner', function (done) {938 helper.request939 .post('/projects/invite')940 .set('apiKey', config.apiKey)941 .set('token', managerObject.token)942 .send({943 inviteid: String(managerObject.invites[1]),944 accept: false,945 })946 .expect(200, (err, res) => {947 if (err) return done(err);948 try {949 const json = JSON.parse(res.text);950 test.object(json)951 .hasProperty('success', true);952 done();953 } catch (error) {954 done(error);955 }956 });957 });958 it('removes invite from owner afterwards and does not add project to owner', function (done) {959 db.findUser({ email: managerEmail })960 .select('+token')961 .then((object) => {962 managerObject = object;963 const objectifiedManager = managerObject.toObject();964 test.object(objectifiedManager)965 .array(objectifiedManager.invites)966 .hasLength(1)967 .array(objectifiedManager.projects)968 .hasLength(1);969 done();970 })971 .catch(done);972 });973 it('correctly accepts invite for client', function (done) {974 const firstClient = clientObjects[0];975 helper.request976 .post('/projects/invite')977 .set('apiKey', config.apiKey)978 .set('token', firstClient.token)979 .send({980 inviteid: String(firstClient.invites[0]),981 accept: true,982 })983 .expect(200, (err, res) => {984 if (err) return done(err);985 try {986 const json = JSON.parse(res.text);987 test.object(json)988 .hasProperty('success', true);989 done();990 } catch (error) {991 done(error);992 }993 });994 });995 it('removes invite from client afterwards and adds project to client', function (done) {996 db.findUser({ email: clientEmails[0] })997 .select('+token')998 .then((object) => {999 const clientObject = object;1000 clientObjects[0] = clientObject;1001 const objectifiedClient = clientObject.toObject();1002 test.object(objectifiedClient)1003 .array(objectifiedClient.invites)1004 .hasLength(1)1005 .array(objectifiedClient.projects)1006 .hasLength(1);1007 done();1008 })1009 .catch(done);1010 });1011 it('correctly rejects invite for client', function (done) {1012 const secondClient = clientObjects[1];1013 helper.request1014 .post('/projects/invite')1015 .set('apiKey', config.apiKey)1016 .set('token', secondClient.token)1017 .send({1018 inviteid: String(secondClient.invites[0]),1019 accept: false,1020 })1021 .expect(200, (err, res) => {1022 if (err) return done(err);1023 try {1024 const json = JSON.parse(res.text);1025 test.object(json)1026 .hasProperty('success', true);1027 done();1028 } catch (error) {1029 done(error);1030 }1031 });1032 });1033 it('removes invite from client afterwards and does not add project to client', function (done) {1034 db.findUser({ email: clientEmails[1] })1035 .select('+token')1036 .then((object) => {1037 const clientObject = object;1038 clientObjects[1] = clientObject;1039 const objectifiedClient = clientObject.toObject();1040 test.object(objectifiedClient)1041 .array(objectifiedClient.invites)1042 .hasLength(1)1043 .array(objectifiedClient.projects)1044 .hasLength(0);1045 done();1046 })1047 .catch(done);1048 });1049 it('correctly fetches test manager', function (done) {1050 db.findUser({ email: testOwnerEmail })1051 .then(helper.generateJWT)1052 .then((dbuser) => {1053 testOwner = dbuser.toObject();1054 test.object(testOwner)1055 .hasProperty('token')1056 .hasProperty('invites')1057 .array(testOwner.invites)1058 .hasLength(2);1059 done();1060 })1061 .catch(done);1062 });1063 it('allows user to reject owner invite', function (done) {1064 helper.request1065 .post('/projects/invite')1066 .set('apiKey', config.apiKey)1067 .set('token', testOwner.token)1068 .send({1069 inviteid: String(testOwner.invites[0]),1070 accept: true,1071 })1072 .expect(200, (err, res) => {1073 if (err) return done(err);1074 try {1075 const json = JSON.parse(res.text);1076 test.object(json)1077 .hasProperty('success', true);1078 done();1079 } catch (error) {1080 done(error);1081 }1082 });1083 });1084 it('allows user with plan over limit invited as owner to reject invite', function (done) {1085 helper.request1086 .post('/projects/invite')1087 .set('apiKey', config.apiKey)1088 .set('token', testOwner.token)1089 .send({1090 inviteid: String(testOwner.invites[1]),1091 accept: false,1092 })1093 .expect(200, (err, res) => {1094 if (err) return done(err);1095 try {1096 const json = JSON.parse(res.text);1097 test.object(json)1098 .hasProperty('success', true);1099 done();1100 } catch (error) {1101 done(error);1102 }1103 });1104 });1105 });1106 context('DELETE /projects/invite', function () {1107 it('returns an error when providing non existing invite id on delete invite', function (done) {1108 helper.request1109 .delete('/projects/invite')1110 .set('apiKey', config.apiKey)1111 .set('token', user.token)1112 .send({1113 inviteid: '58e73c820a9f165ffc06c1cf',1114 })1115 .expect(400, (err, res) => {1116 if (err) return done(err);1117 try {1118 const json = JSON.parse(res.text);1119 test.object(json)1120 .hasProperty('type', 'INVITE_NOT_FOUND_ERROR');1121 done();1122 } catch (error) {1123 done(error);1124 }1125 });1126 });1127 it('returns an error when providing no invite id on delete invite', function (done) {1128 helper.request1129 .delete('/projects/invite')1130 .set('apiKey', config.apiKey)1131 .set('token', user.token)1132 .send({1133 })1134 .expect(400, (err, res) => {1135 if (err) return done(err);1136 try {1137 const json = JSON.parse(res.text);1138 test.object(json)1139 .hasProperty('type', 'VALIDATION_ERROR');1140 done();1141 } catch (error) {1142 done(error);1143 }1144 });1145 });1146 it('does not allow to delete invite for manager by client', function (done) {1147 helper.request1148 .delete('/projects/invite')1149 .set('apiKey', config.apiKey)1150 .set('token', user.token)1151 .send({1152 inviteid: String(managerObject.invites[0]),1153 })1154 .expect(403, (err, res) => {1155 if (err) return done(err);1156 try {1157 const json = JSON.parse(res.text);1158 test.object(json)1159 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');1160 done();1161 } catch (error) {1162 done(error);1163 }1164 });1165 });1166 it('correctly allows to remove invite for client', function (done) {1167 helper.request1168 .delete('/projects/invite')1169 .set('apiKey', config.apiKey)1170 .set('token', user.token)1171 .send({1172 inviteid: String(clientObjects[2].invites[0]),1173 })1174 .expect(200, (err, res) => {1175 if (err) return done(err);1176 try {1177 const json = JSON.parse(res.text);1178 test.object(json)1179 .hasProperty('success', true);1180 done();1181 } catch (error) {1182 done(error);1183 }1184 });1185 });1186 it('removes invite from client afterwards and does not add project to client', function (done) {1187 db.findUser({ email: clientEmails[2] })1188 .select('+token')1189 .then((object) => {1190 const clientObject = object;1191 clientObjects[2] = clientObject;1192 const objectifiedClient = clientObject.toObject();1193 test.object(objectifiedClient)1194 .array(objectifiedClient.invites)1195 .hasLength(1)1196 .array(objectifiedClient.projects)1197 .hasLength(0);1198 done();1199 })1200 .catch(done);1201 });1202 });1203 context('GET /projects/project', function () {1204 it('returns error on getting project with empty project id', function (done) {1205 helper.request1206 .get('/projects/project')1207 .set('apiKey', config.apiKey)1208 .set('token', user.token)1209 .expect(400, (err, res) => {1210 if (err) return done(err);1211 try {1212 const json = JSON.parse(res.text);1213 test.object(json)1214 .hasProperty('type', 'VALIDATION_ERROR');1215 done();1216 } catch (error) {1217 done(error);1218 }1219 });1220 });1221 it('returns error on getting project with non existing project id', function (done) {1222 helper.request1223 .get('/projects/project')1224 .set('apiKey', config.apiKey)1225 .set('token', user.token)1226 .query({1227 projectid: '58e73c820a9f165ffc06c1cf',1228 })1229 .expect(400, (err, res) => {1230 if (err) return done(err);1231 try {1232 const json = JSON.parse(res.text);1233 test.object(json)1234 .hasProperty('type', 'PROJECT_NOT_FOUND_ERROR');1235 done();1236 } catch (error) {1237 done(error);1238 }1239 });1240 });1241 it('grabs user', function (done) {1242 db.findUser({ email })1243 .select('+token')1244 .then((dbuser) => {1245 user = dbuser;1246 done();1247 })1248 .catch(done);1249 });1250 it('returns error on getting project that does not include getter', function (done) {1251 helper.request1252 .get('/projects/project')1253 .set('apiKey', config.apiKey)1254 .set('token', clientObjects[2].token)1255 .query({1256 projectid: String(user.projects[0]),1257 })1258 .expect(403, (err, res) => {1259 if (err) return done(err);1260 try {1261 const json = JSON.parse(res.text);1262 test.object(json)1263 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');1264 done();1265 } catch (error) {1266 done(error);1267 }1268 });1269 });1270 it('correctly fetches project by client', function (done) {1271 helper.request1272 .get('/projects/project')1273 .set('apiKey', config.apiKey)1274 .set('token', user.token)1275 .query({1276 projectid: String(user.projects[0]),1277 })1278 .expect(200, (err, res) => {1279 if (err) return done(err);1280 try {1281 const json = JSON.parse(res.text);1282 test.object(json)1283 .hasProperty('title', 'Test client')1284 .hasProperty('description', 'Test project description')1285 .hasProperty('image', 'key/to/test/image.png')1286 .hasProperty('isFinished', false)1287 .hasProperty('canEdit', false);1288 done();1289 } catch (error) {1290 done(error);1291 }1292 });1293 });1294 it('correctly fetches project by manager', function (done) {1295 helper.request1296 .get('/projects/project')1297 .set('apiKey', config.apiKey)1298 .set('token', managerObject.token)1299 .query({1300 projectid: String(managerObject.projects[0]),1301 })1302 .expect(200, (err, res) => {1303 if (err) return done(err);1304 try {1305 const json = JSON.parse(res.text);1306 test.object(json)1307 .hasProperty('title', 'Test client almost empty')1308 .hasNotProperty('description')1309 .hasNotProperty('image')1310 .hasProperty('isFinished', false)1311 .hasProperty('canEdit', true);1312 done();1313 } catch (error) {1314 done(error);1315 }1316 });1317 });1318 });1319 context('GET /projects', function () {1320 it('correctly fetches list of projects', function (done) {1321 helper.request1322 .get('/projects')1323 .set('apiKey', config.apiKey)1324 .set('token', user.token)1325 .expect(200, (err, res) => {1326 if (err) return done(err);1327 try {1328 const json = JSON.parse(res.text);1329 test.array(json)1330 .hasLength(7)1331 .object(json[0])1332 .hasProperty('canEdit', true)1333 .object(json[1])1334 .hasProperty('canEdit', false)1335 .object(json[2])1336 .hasProperty('canEdit', false)1337 .object(json[3])1338 .hasProperty('canEdit', true)1339 .object(json[4])1340 .hasProperty('canEdit', false);1341 done();1342 } catch (error) {1343 done(error);1344 }1345 });1346 });1347 it('correctly fetches list of projects with skip and limit', function (done) {1348 helper.request1349 .get('/projects')1350 .set('apiKey', config.apiKey)1351 .set('token', user.token)1352 .query({1353 skip: 4,1354 limit: 1,1355 })1356 .expect(200, (err, res) => {1357 if (err) return done(err);1358 try {1359 const json = JSON.parse(res.text);1360 test.array(json)1361 .hasLength(1)1362 .object(json[0])1363 .hasProperty('canEdit', false);1364 done();1365 } catch (error) {1366 done(error);1367 }1368 });1369 });1370 it('correctly fetches empty list of projects with skip over the number of projects', function (done) {1371 helper.request1372 .get('/projects')1373 .set('apiKey', config.apiKey)1374 .set('token', user.token)1375 .query({1376 skip: 7,1377 })1378 .expect(200, (err, res) => {1379 if (err) return done(err);1380 try {1381 const json = JSON.parse(res.text);1382 test.array(json)1383 .hasLength(0);1384 done();1385 } catch (error) {1386 done(error);1387 }1388 });1389 });1390 it('correctly fetches list of projects with query', function (done) {1391 helper.request1392 .get('/projects')1393 .set('apiKey', config.apiKey)1394 .set('token', user.token)1395 .query({1396 query: 'Test client',1397 })1398 .expect(200, (err, res) => {1399 if (err) return done(err);1400 try {1401 const json = JSON.parse(res.text);1402 test.array(json)1403 .hasLength(3);1404 done();1405 } catch (error) {1406 done(error);1407 }1408 });1409 });1410 it('correctly fetches list of projects with empty string query', function (done) {1411 helper.request1412 .get('/projects')1413 .set('apiKey', config.apiKey)1414 .set('token', user.token)1415 .query({1416 query: '',1417 })1418 .expect(200, (err, res) => {1419 if (err) return done(err);1420 try {1421 const json = JSON.parse(res.text);1422 test.array(json)1423 .hasLength(7);1424 done();1425 } catch (error) {1426 done(error);1427 }1428 });1429 });1430 it('correctly fetches list of projects with query, skip and limit', function (done) {1431 helper.request1432 .get('/projects')1433 .set('apiKey', config.apiKey)1434 .set('token', user.token)1435 .query({1436 query: 'Test client',1437 skip: 1,1438 limit: 2,1439 })1440 .expect(200, (err, res) => {1441 if (err) return done(err);1442 try {1443 const json = JSON.parse(res.text);1444 test.array(json)1445 .hasLength(2)1446 .object(json[0])1447 .hasProperty('title', 'Test client third')1448 .object(json[1])1449 .hasProperty('title', 'Test client');1450 done();1451 } catch (error) {1452 done(error);1453 }1454 });1455 });1456 it('correctly fetches list of projects with type all', function (done) {1457 helper.request1458 .get('/projects')1459 .set('apiKey', config.apiKey)1460 .set('token', user.token)1461 .query({1462 type: 'all',1463 })1464 .expect(200, (err, res) => {1465 if (err) return done(err);1466 try {1467 const json = JSON.parse(res.text);1468 test.array(json)1469 .hasLength(7);1470 done();1471 } catch (error) {1472 done(error);1473 }1474 });1475 });1476 it('correctly fetches list of projects with type live', function (done) {1477 helper.request1478 .get('/projects')1479 .set('apiKey', config.apiKey)1480 .set('token', user.token)1481 .query({1482 type: 'live',1483 })1484 .expect(200, (err, res) => {1485 if (err) return done(err);1486 try {1487 const json = JSON.parse(res.text);1488 test.array(json)1489 .hasLength(7);1490 done();1491 } catch (error) {1492 done(error);1493 }1494 });1495 });1496 it('correctly fetches list of projects with type is empty string', function (done) {1497 helper.request1498 .get('/projects')1499 .set('apiKey', config.apiKey)1500 .set('token', user.token)1501 .query({1502 type: '',1503 })1504 .expect(200, (err, res) => {1505 if (err) return done(err);1506 try {1507 const json = JSON.parse(res.text);1508 test.array(json)1509 .hasLength(7);1510 done();1511 } catch (error) {1512 done(error);1513 }1514 });1515 });1516 it('correctly fetches list of projects with type finished', function (done) {1517 helper.request1518 .get('/projects')1519 .set('apiKey', config.apiKey)1520 .set('token', user.token)1521 .query({1522 type: 'finished',1523 })1524 .expect(200, (err, res) => {1525 if (err) return done(err);1526 try {1527 const json = JSON.parse(res.text);1528 test.array(json)1529 .hasLength(0);1530 done();1531 } catch (error) {1532 done(error);1533 }1534 });1535 });1536 it('returns error when fetching projects with strange type', function (done) {1537 helper.request1538 .get('/projects')1539 .set('apiKey', config.apiKey)1540 .set('token', user.token)1541 .query({1542 type: 'strange',1543 })1544 .expect(400, (err, res) => {1545 if (err) return done(err);1546 try {1547 const json = JSON.parse(res.text);1548 test.object(json)1549 .hasProperty('type', 'VALIDATION_ERROR');1550 done();1551 } catch (error) {1552 done(error);1553 }1554 });1555 });1556 it('correctly fetches list of invites for user with no invites', function (done) {1557 helper.request1558 .get('/projects/invites')1559 .set('apiKey', config.apiKey)1560 .set('token', user.token)1561 .expect(200, (err, res) => {1562 if (err) return done(err);1563 try {1564 const json = JSON.parse(res.text);1565 test.array(json)1566 .hasLength(0);1567 done();1568 } catch (error) {1569 done(error);1570 }1571 });1572 });1573 it('correctly fetches list of invites for user with invites', function (done) {1574 helper.request1575 .get('/projects/invites')1576 .set('apiKey', config.apiKey)1577 .set('token', managerObject.token)1578 .expect(200, (err, res) => {1579 if (err) return done(err);1580 try {1581 const json = JSON.parse(res.text);1582 test.array(json)1583 .hasLength(1);1584 done();1585 } catch (error) {1586 done(error);1587 }1588 });1589 });1590 });1591 context('POST /projects/managers', function () {1592 it('grabs test projects', function (done) {1593 helper.request1594 .get('/projects')1595 .set('apiKey', config.apiKey)1596 .set('token', user.token)1597 .expect(200, (err, res) => {1598 if (err) return done(err);1599 try {1600 const json = JSON.parse(res.text);1601 testProject = json[0];1602 testProjectCannotEdit = json[1];1603 test.object(testProject)1604 .hasProperty('canEdit', true)1605 .hasProperty('title', 'Test manager');1606 test.object(testProjectCannotEdit)1607 .hasProperty('canEdit', false);1608 done();1609 } catch (error) {1610 done(error);1611 }1612 });1613 });1614 it('returns error when adding managers without project id', function (done) {1615 helper.request1616 .post('/projects/managers')1617 .set('apiKey', config.apiKey)1618 .set('token', user.token)1619 .send({1620 managers: [managerEmail, managerEmail, secondManagerEmail, demoEmail],1621 })1622 .expect(400, (err, res) => {1623 if (err) return done(err);1624 try {1625 const json = JSON.parse(res.text);1626 test.object(json)1627 .hasProperty('type', 'VALIDATION_ERROR');1628 done();1629 } catch (error) {1630 done(error);1631 }1632 });1633 });1634 it('returns error when adding managers without managers list', function (done) {1635 helper.request1636 .post('/projects/managers')1637 .set('apiKey', config.apiKey)1638 .set('token', user.token)1639 .send({1640 projectid: testProject._id,1641 })1642 .expect(400, (err, res) => {1643 if (err) return done(err);1644 try {1645 const json = JSON.parse(res.text);1646 test.object(json)1647 .hasProperty('type', 'VALIDATION_ERROR');1648 done();1649 } catch (error) {1650 done(error);1651 }1652 });1653 });1654 it('returns error when adding managers with empty managers array', function (done) {1655 helper.request1656 .post('/projects/managers')1657 .set('apiKey', config.apiKey)1658 .set('token', user.token)1659 .send({1660 projectid: testProject._id,1661 managers: [],1662 })1663 .expect(400, (err, res) => {1664 if (err) return done(err);1665 try {1666 const json = JSON.parse(res.text);1667 test.object(json)1668 .hasProperty('type', 'VALIDATION_ERROR');1669 done();1670 } catch (error) {1671 done(error);1672 }1673 });1674 });1675 it('returns error when adding managers to project without access', function (done) {1676 helper.request1677 .post('/projects/managers')1678 .set('apiKey', config.apiKey)1679 .set('token', user.token)1680 .send({1681 projectid: testProjectCannotEdit._id,1682 managers: [managerEmail],1683 })1684 .expect(403, (err, res) => {1685 if (err) return done(err);1686 try {1687 const json = JSON.parse(res.text);1688 test.object(json)1689 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');1690 done();1691 } catch (error) {1692 done(error);1693 }1694 });1695 });1696 it('correctly invites two managers', function (done) {1697 helper.request1698 .post('/projects/managers')1699 .set('apiKey', config.apiKey)1700 .set('token', user.token)1701 .send({1702 projectid: testProject._id,1703 managers: [managerEmail, managerEmail, secondManagerEmail, demoEmail],1704 })1705 .expect(200, (err, res) => {1706 if (err) return done(err);1707 try {1708 const json = JSON.parse(res.text);1709 test.object(json)1710 .hasProperty('success', true);1711 done();1712 } catch (error) {1713 done(error);1714 }1715 });1716 });1717 it('adds invites to project', function (done) {1718 db.getProject(user._id, testProject._id)1719 .then((project) => {1720 testProject = project.toObject();1721 test.object(testProject)1722 .hasProperty('invites')1723 .array(testProject.invites)1724 .hasLength(3);1725 done();1726 })1727 .catch(done);1728 });1729 it('adds invites to managers', function (done) {1730 Promise.all([1731 db.findUser({ email: managerEmail }).select('+token'),1732 db.findUser({ email: secondManagerEmail }).then(helper.generateJWT),1733 ]).then((managers) => {1734 managerObject = managers[0].toObject();1735 secondManagerObject = managers[1].toObject();1736 test1737 .array(managerObject.invites)1738 .hasLength(2)1739 .array(secondManagerObject.invites)1740 .hasLength(1);1741 done();1742 })1743 .catch(done);1744 });1745 it('does not do anything when inviting the same managers again', function (done) {1746 helper.request1747 .post('/projects/managers')1748 .set('apiKey', config.apiKey)1749 .set('token', user.token)1750 .send({1751 projectid: testProject._id,1752 managers: [managerEmail, managerEmail, secondManagerEmail, demoEmail],1753 })1754 .expect(200, (err, res) => {1755 if (err) return done(err);1756 try {1757 const json = JSON.parse(res.text);1758 test.object(json)1759 .hasProperty('success', true);1760 done();1761 } catch (error) {1762 done(error);1763 }1764 });1765 });1766 it('project still has same number of invites', function (done) {1767 db.getProject(user._id, testProject._id)1768 .then((project) => {1769 testProject = project.toObject();1770 test.object(testProject)1771 .hasProperty('invites')1772 .array(testProject.invites)1773 .hasLength(3);1774 done();1775 })1776 .catch(done);1777 });1778 it('managers still have same number of invites', function (done) {1779 Promise.all([1780 db.findUser({ email: managerEmail }).select('+token'),1781 db.findUser({ email: secondManagerEmail }).select('+token'),1782 ]).then((managers) => {1783 managerObject = managers[0].toObject();1784 secondManagerObject = managers[1].toObject();1785 test1786 .array(managerObject.invites)1787 .hasLength(2)1788 .array(secondManagerObject.invites)1789 .hasLength(1);1790 done();1791 })1792 .catch(done);1793 });1794 it('correctly accepts invite from manager', function (done) {1795 helper.request1796 .post('/projects/invite')1797 .set('apiKey', config.apiKey)1798 .set('token', secondManagerObject.token)1799 .send({1800 inviteid: String(secondManagerObject.invites[0]),1801 accept: true,1802 })1803 .expect(200, (err, res) => {1804 if (err) return done(err);1805 try {1806 const json = JSON.parse(res.text);1807 test.object(json)1808 .hasProperty('success', true);1809 done();1810 } catch (error) {1811 done(error);1812 }1813 });1814 });1815 it('adds manager to project afterwards', function (done) {1816 db.getProject(secondManagerObject._id, testProject._id)1817 .then((project) => {1818 testProject = project.toObject();1819 test.object(testProject)1820 .array(testProject.managers)1821 .hasLength(1);1822 done();1823 })1824 .catch(done);1825 });1826 it('correctly fetches project by manager', function (done) {1827 helper.request1828 .get('/projects/project')1829 .set('apiKey', config.apiKey)1830 .set('token', secondManagerObject.token)1831 .query({1832 projectid: String(testProject._id),1833 })1834 .expect(200, (err, res) => {1835 if (err) return done(err);1836 try {1837 const json = JSON.parse(res.text);1838 test.object(json)1839 .hasProperty('canEdit', true);1840 done();1841 } catch (error) {1842 done(error);1843 }1844 });1845 });1846 it('correctly removes all invites from test project', function (done) {1847 Promise.map(testProject.invites, invite =>1848 new Promise((resolve, reject) => {1849 helper.request1850 .delete('/projects/invite')1851 .set('apiKey', config.apiKey)1852 .set('token', user.token)1853 .send({ inviteid: String(invite._id) })1854 .expect(200, (err, res) => {1855 if (err) return reject(err);1856 try {1857 const json = JSON.parse(res.text);1858 test.object(json)1859 .hasProperty('success', true);1860 resolve();1861 } catch (error) {1862 reject(error);1863 }1864 });1865 }), { concurrency: 1 })1866 .then(() => {1867 done();1868 })1869 .catch(done);1870 });1871 });1872 context('DELETE /projects/manager', function () {1873 it('correctly deletes manager from test project', function (done) {1874 helper.request1875 .delete('/projects/manager')1876 .set('apiKey', config.apiKey)1877 .set('token', user.token)1878 .send({1879 projectid: String(testProject._id),1880 managerid: String(secondManagerObject._id),1881 })1882 .expect(200, (err, res) => {1883 if (err) return done(err);1884 try {1885 const json = JSON.parse(res.text);1886 test.object(json)1887 .hasProperty('success', true);1888 done();1889 } catch (error) {1890 done(error);1891 }1892 });1893 });1894 });1895 context('DELETE /projects/client', function () {1896 it('correctly deletes client from test project', function (done) {1897 helper.request1898 .delete('/projects/client')1899 .set('apiKey', config.apiKey)1900 .set('token', user.token)1901 .send({1902 projectid: String(testProject._id),1903 clientid: String(testProject.clients[0]._id),1904 })1905 .expect(200, (err, res) => {1906 if (err) return done(err);1907 try {1908 const json = JSON.parse(res.text);1909 test.object(json)1910 .hasProperty('success', true);1911 done();1912 } catch (error) {1913 done(error);1914 }1915 });1916 });1917 it('has no managers and clients afterwards', function (done) {1918 db.getProject(user._id, testProject._id)1919 .then((project) => {1920 testProject = project.toObject();1921 test.object(testProject)1922 .array(testProject.invites)1923 .hasLength(0)1924 .array(testProject.clients)1925 .hasLength(0)1926 .array(testProject.managers)1927 .hasLength(0);1928 done();1929 })1930 .catch(done);1931 });1932 });1933 context('POST /projects/client', function () {1934 it('returns error when adding clients without project id', function (done) {1935 helper.request1936 .post('/projects/clients')1937 .set('apiKey', config.apiKey)1938 .set('token', user.token)1939 .send({1940 clients: [managerEmail, managerEmail, secondManagerEmail, demoEmail],1941 })1942 .expect(400, (err, res) => {1943 if (err) return done(err);1944 try {1945 const json = JSON.parse(res.text);1946 test.object(json)1947 .hasProperty('type', 'VALIDATION_ERROR');1948 done();1949 } catch (error) {1950 done(error);1951 }1952 });1953 });1954 it('returns error when adding clients without clients list', function (done) {1955 helper.request1956 .post('/projects/clients')1957 .set('apiKey', config.apiKey)1958 .set('token', user.token)1959 .send({1960 projectid: testProject._id,1961 })1962 .expect(400, (err, res) => {1963 if (err) return done(err);1964 try {1965 const json = JSON.parse(res.text);1966 test.object(json)1967 .hasProperty('type', 'VALIDATION_ERROR');1968 done();1969 } catch (error) {1970 done(error);1971 }1972 });1973 });1974 it('returns error when adding clients with empty clients array', function (done) {1975 helper.request1976 .post('/projects/clients')1977 .set('apiKey', config.apiKey)1978 .set('token', user.token)1979 .send({1980 projectid: testProject._id,1981 clients: [],1982 })1983 .expect(400, (err, res) => {1984 if (err) return done(err);1985 try {1986 const json = JSON.parse(res.text);1987 test.object(json)1988 .hasProperty('type', 'VALIDATION_ERROR');1989 done();1990 } catch (error) {1991 done(error);1992 }1993 });1994 });1995 it('returns error when adding clients to project without access', function (done) {1996 helper.request1997 .post('/projects/clients')1998 .set('apiKey', config.apiKey)1999 .set('token', user.token)2000 .send({2001 projectid: testProjectCannotEdit._id,2002 clients: [managerEmail],2003 })2004 .expect(403, (err, res) => {2005 if (err) return done(err);2006 try {2007 const json = JSON.parse(res.text);2008 test.object(json)2009 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');2010 done();2011 } catch (error) {2012 done(error);2013 }2014 });2015 });2016 it('correctly invites two clients', function (done) {2017 helper.request2018 .post('/projects/clients')2019 .set('apiKey', config.apiKey)2020 .set('token', user.token)2021 .send({2022 projectid: testProject._id,2023 clients: [managerEmail, managerEmail, secondManagerEmail, demoEmail],2024 })2025 .expect(200, (err, res) => {2026 if (err) return done(err);2027 try {2028 const json = JSON.parse(res.text);2029 test.object(json)2030 .hasProperty('success', true);2031 done();2032 } catch (error) {2033 done(error);2034 }2035 });2036 });2037 it('adds invites to project', function (done) {2038 db.getProject(user._id, testProject._id)2039 .then((project) => {2040 testProject = project.toObject();2041 test.object(testProject)2042 .hasProperty('invites')2043 .array(testProject.invites)2044 .hasLength(2);2045 done();2046 })2047 .catch(done);2048 });2049 it('adds invites to clients', function (done) {2050 Promise.all([2051 db.findUser({ email: managerEmail }).select('+token'),2052 db.findUser({ email: secondManagerEmail }).select('+token'),2053 ]).then((clients) => {2054 managerObject = clients[0].toObject();2055 secondManagerObject = clients[1].toObject();2056 test2057 .array(managerObject.invites)2058 .hasLength(2)2059 .array(secondManagerObject.invites)2060 .hasLength(1);2061 done();2062 })2063 .catch(done);2064 });2065 it('does not do anything when inviting the same clients again', function (done) {2066 helper.request2067 .post('/projects/clients')2068 .set('apiKey', config.apiKey)2069 .set('token', user.token)2070 .send({2071 projectid: testProject._id,2072 clients: [managerEmail, managerEmail, secondManagerEmail, demoEmail],2073 })2074 .expect(200, (err, res) => {2075 if (err) return done(err);2076 try {2077 const json = JSON.parse(res.text);2078 test.object(json)2079 .hasProperty('success', true);2080 done();2081 } catch (error) {2082 done(error);2083 }2084 });2085 });2086 it('project still has same number of invites', function (done) {2087 db.getProject(user._id, testProject._id)2088 .then((project) => {2089 testProject = project.toObject();2090 test.object(testProject)2091 .hasProperty('invites')2092 .array(testProject.invites)2093 .hasLength(2);2094 done();2095 })2096 .catch(done);2097 });2098 it('clients still have same number of invites', function (done) {2099 Promise.all([2100 db.findUser({ email: managerEmail }).select('+token'),2101 db.findUser({ email: secondManagerEmail }).select('+token'),2102 ]).then((clients) => {2103 managerObject = clients[0].toObject();2104 secondManagerObject = clients[1].toObject();2105 test2106 .array(managerObject.invites)2107 .hasLength(2)2108 .array(secondManagerObject.invites)2109 .hasLength(1);2110 done();2111 })2112 .catch(done);2113 });2114 it('correctly accepts invite from client', function (done) {2115 helper.request2116 .post('/projects/invite')2117 .set('apiKey', config.apiKey)2118 .set('token', secondManagerObject.token)2119 .send({2120 inviteid: String(secondManagerObject.invites[0]),2121 accept: true,2122 })2123 .expect(200, (err, res) => {2124 if (err) return done(err);2125 try {2126 const json = JSON.parse(res.text);2127 test.object(json)2128 .hasProperty('success', true);2129 done();2130 } catch (error) {2131 done(error);2132 }2133 });2134 });2135 it('adds client to project afterwards', function (done) {2136 db.getProject(secondManagerObject._id, testProject._id)2137 .then((project) => {2138 testProject = project.toObject();2139 test.object(testProject)2140 .array(testProject.clients)2141 .hasLength(1);2142 done();2143 })2144 .catch(done);2145 });2146 it('correctly fetches project by client', function (done) {2147 helper.request2148 .get('/projects/project')2149 .set('apiKey', config.apiKey)2150 .set('token', secondManagerObject.token)2151 .query({2152 projectid: String(testProject._id),2153 })2154 .expect(200, (err, res) => {2155 if (err) return done(err);2156 try {2157 const json = JSON.parse(res.text);2158 test.object(json)2159 .hasProperty('canEdit', false);2160 done();2161 } catch (error) {2162 done(error);2163 }2164 });2165 });2166 it('correctly removes all invites from test project', function (done) {2167 Promise.map(testProject.invites, invite =>2168 new Promise((resolve, reject) => {2169 helper.request2170 .delete('/projects/invite')2171 .set('apiKey', config.apiKey)2172 .set('token', user.token)2173 .send({ inviteid: String(invite._id) })2174 .expect(200, (err, res) => {2175 if (err) return reject(err);2176 try {2177 const json = JSON.parse(res.text);2178 test.object(json)2179 .hasProperty('success', true);2180 resolve();2181 } catch (error) {2182 reject(error);2183 }2184 });2185 }), { concurrency: 1 })2186 .then(() => {2187 done();2188 })2189 .catch(done);2190 });2191 });2192 context('POST /projects/finish', function () {2193 it('returns error when tries to finish the project by client', function (done) {2194 helper.request2195 .post('/projects/finish')2196 .set('apiKey', config.apiKey)2197 .set('token', secondManagerObject.token)2198 .send({ projectid: String(testProject._id) })2199 .expect(403, (err, res) => {2200 if (err) return done(err);2201 try {2202 const json = JSON.parse(res.text);2203 test.object(json)2204 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');2205 done();2206 } catch (error) {2207 done(error);2208 }2209 });2210 });2211 it('correctly finishes the project', function (done) {2212 helper.request2213 .post('/projects/finish')2214 .set('apiKey', config.apiKey)2215 .set('token', user.token)2216 .send({ projectid: String(testProject._id) })2217 .expect(200, (err, res) => {2218 if (err) return done(err);2219 try {2220 const json = JSON.parse(res.text);2221 test.object(json);2222 done();2223 } catch (error) {2224 done(error);2225 }2226 });2227 });2228 it('has test project finished then', function (done) {2229 db.getProject(user._id, testProject._id)2230 .then((project) => {2231 testProject = project.toObject();2232 test.object(testProject)2233 .hasProperty('isFinished', true);2234 done();2235 })2236 .catch(done);2237 });2238 it('correctly finishes the project again', function (done) {2239 helper.request2240 .post('/projects/finish')2241 .set('apiKey', config.apiKey)2242 .set('token', user.token)2243 .send({ projectid: String(testProject._id) })2244 .expect(200, (err, res) => {2245 if (err) return done(err);2246 try {2247 const json = JSON.parse(res.text);2248 test.object(json);2249 done();2250 } catch (error) {2251 done(error);2252 }2253 });2254 });2255 it('still has test project finished then', function (done) {2256 db.getProject(user._id, testProject._id)2257 .then((project) => {2258 testProject = project.toObject();2259 test.object(testProject)2260 .hasProperty('isFinished', true);2261 done();2262 })2263 .catch(done);2264 });2265 });2266 context('POST /projects/revive', function () {2267 it('returns error when tries to revive the project by client', function (done) {2268 helper.request2269 .post('/projects/revive')2270 .set('apiKey', config.apiKey)2271 .set('token', secondManagerObject.token)2272 .send({ projectid: String(testProject._id) })2273 .expect(403, (err, res) => {2274 if (err) return done(err);2275 try {2276 const json = JSON.parse(res.text);2277 test.object(json)2278 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');2279 done();2280 } catch (error) {2281 done(error);2282 }2283 });2284 });2285 it('correctly revives the project', function (done) {2286 helper.request2287 .post('/projects/revive')2288 .set('apiKey', config.apiKey)2289 .set('token', user.token)2290 .send({ projectid: String(testProject._id) })2291 .expect(200, (err, res) => {2292 if (err) return done(err);2293 try {2294 const json = JSON.parse(res.text);2295 test.object(json);2296 done();2297 } catch (error) {2298 done(error);2299 }2300 });2301 });2302 it('has test project revived then', function (done) {2303 db.getProject(user._id, testProject._id)2304 .then((project) => {2305 testProject = project.toObject();2306 test.object(testProject)2307 .hasProperty('isFinished', false);2308 done();2309 })2310 .catch(done);2311 });2312 it('correctly revives the project again', function (done) {2313 helper.request2314 .post('/projects/revive')2315 .set('apiKey', config.apiKey)2316 .set('token', user.token)2317 .send({ projectid: String(testProject._id) })2318 .expect(200, (err, res) => {2319 if (err) return done(err);2320 try {2321 const json = JSON.parse(res.text);2322 test.object(json);2323 done();2324 } catch (error) {2325 done(error);2326 }2327 });2328 });2329 it('still has test project finished then', function (done) {2330 db.getProject(user._id, testProject._id)2331 .then((project) => {2332 testProject = project.toObject();2333 test.object(testProject)2334 .hasProperty('isFinished', false);2335 done();2336 })2337 .catch(done);2338 });2339 });2340 context('POST /projects/leave', function () {2341 it('returns error when tries to leave the project by owner', function (done) {2342 helper.request2343 .post('/projects/leave')2344 .set('apiKey', config.apiKey)2345 .set('token', user.token)2346 .send({ projectid: String(testProject._id) })2347 .expect(403, (err, res) => {2348 if (err) return done(err);2349 try {2350 const json = JSON.parse(res.text);2351 test.object(json)2352 .hasProperty('type', 'LEAVE_AS_OWNER_ERROR');2353 done();2354 } catch (error) {2355 done(error);2356 }2357 });2358 });2359 it('correctly leaves the project as client', function (done) {2360 helper.request2361 .post('/projects/leave')2362 .set('apiKey', config.apiKey)2363 .set('token', secondManagerObject.token)2364 .send({ projectid: String(testProject._id) })2365 .expect(200, (err, res) => {2366 if (err) return done(err);2367 try {2368 const json = JSON.parse(res.text);2369 test.object(json)2370 .hasProperty('success', true);2371 done();2372 } catch (error) {2373 done(error);2374 }2375 });2376 });2377 it('does not have client on project anymore', function (done) {2378 db.getProject(user._id, testProject._id)2379 .then((project) => {2380 testProject = project.toObject();2381 test.object(testProject)2382 .array(testProject.clients)2383 .hasLength(0);2384 done();2385 })2386 .catch(done);2387 });2388 it('correctly leaves the project as manager', function (done) {2389 db.getProject(user._id, testProject._id)2390 .then((project) => {2391 project.managers.push(managerObject._id);2392 return project.save()2393 .then((dbproject) => {2394 testProject = dbproject.toObject();2395 });2396 })2397 .then(() => {2398 helper.request2399 .post('/projects/leave')2400 .set('apiKey', config.apiKey)2401 .set('token', managerObject.token)2402 .send({ projectid: String(testProject._id) })2403 .expect(200, (err, res) => {2404 if (err) return done(err);2405 try {2406 const json = JSON.parse(res.text);2407 test.object(json)2408 .hasProperty('success', true);2409 done();2410 } catch (error) {2411 done(error);2412 }2413 });2414 })2415 .catch(done);2416 });2417 it('does not have manager on project anymore', function (done) {2418 db.getProject(user._id, testProject._id)2419 .then((project) => {2420 testProject = project.toObject();2421 test.object(testProject)2422 .array(testProject.managers)2423 .hasLength(0);2424 done();2425 })2426 .catch(done);2427 });2428 });2429 context('PUT /projects', function () {2430 it('adds manager and client to project', function (done) {2431 db.getProject(user._id, testProject._id)2432 .then((project) => {2433 project.managers.push(managerObject._id);2434 project.clients.push(secondManagerObject._id);2435 return project.save();2436 })2437 .then((project) => {2438 testProject = project.toObject();2439 test.object(testProject)2440 .array(testProject.managers)2441 .hasLength(1)2442 .array(testProject.clients)2443 .hasLength(1);2444 done();2445 })2446 .catch(done);2447 });2448 it('returns error when client tries to edit project', function (done) {2449 helper.request2450 .put('/projects')2451 .set('apiKey', config.apiKey)2452 .set('token', secondManagerObject.token)2453 .send({2454 projectid: String(testProject._id),2455 title: 'Should fail',2456 description: 'Desctiption for should fail',2457 progressEnabled: true,2458 })2459 .expect(403, (err, res) => {2460 if (err) return done(err);2461 try {2462 const json = JSON.parse(res.text);2463 test.object(json)2464 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');2465 done();2466 } catch (error) {2467 done(error);2468 }2469 });2470 });2471 it('successfully edits project as manager', function (done) {2472 helper.request2473 .put('/projects')2474 .set('apiKey', config.apiKey)2475 .set('token', managerObject.token)2476 .send({2477 projectid: String(testProject._id),2478 title: 'Should work',2479 description: 'As manager',2480 progressEnabled: true,2481 })2482 .expect(200, (err, res) => {2483 if (err) return done(err);2484 try {2485 const json = JSON.parse(res.text);2486 test.object(json)2487 .hasProperty('title', 'Should work')2488 .hasProperty('description', 'As manager')2489 .hasNotProperty('image');2490 done();2491 } catch (error) {2492 done(error);2493 }2494 });2495 });2496 it('successfully edits project as owner', function (done) {2497 helper.request2498 .put('/projects')2499 .set('apiKey', config.apiKey)2500 .set('token', managerObject.token)2501 .send({2502 projectid: String(testProject._id),2503 title: 'Should work too',2504 description: 'As client',2505 progressEnabled: true,2506 })2507 .expect(200, (err, res) => {2508 if (err) return done(err);2509 try {2510 const json = JSON.parse(res.text);2511 test.object(json)2512 .hasProperty('title', 'Should work too')2513 .hasProperty('description', 'As client')2514 .hasNotProperty('image');2515 done();2516 } catch (error) {2517 done(error);2518 }2519 });2520 });2521 });2522 context('PUT /projects/progress', function () {2523 it('returns error when client tries to edit progress', function (done) {2524 helper.request2525 .put('/projects/progress')2526 .set('apiKey', config.apiKey)2527 .set('token', secondManagerObject.token)2528 .send({2529 projectid: String(testProject._id),2530 progress: '99',2531 })2532 .expect(403, (err, res) => {2533 if (err) return done(err);2534 try {2535 const json = JSON.parse(res.text);2536 test.object(json)2537 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');2538 done();2539 } catch (error) {2540 done(error);2541 }2542 });2543 });2544 it('successfully edits progress as manager', function (done) {2545 helper.request2546 .put('/projects/progress')2547 .set('apiKey', config.apiKey)2548 .set('token', managerObject.token)2549 .send({2550 projectid: String(testProject._id),2551 progress: '99',2552 })2553 .expect(200, (err, res) => {2554 if (err) return done(err);2555 try {2556 const json = JSON.parse(res.text);2557 test.object(json)2558 .hasProperty('success', true);2559 done();2560 } catch (error) {2561 done(error);2562 }2563 });2564 });2565 it('successfully edits progress as owner', function (done) {2566 helper.request2567 .put('/projects/progress')2568 .set('apiKey', config.apiKey)2569 .set('token', user.token)2570 .send({2571 projectid: String(testProject._id),2572 progress: '100',2573 })2574 .expect(200, (err, res) => {2575 if (err) return done(err);2576 try {2577 const json = JSON.parse(res.text);2578 test.object(json)2579 .hasProperty('success', true);2580 done();2581 } catch (error) {2582 done(error);2583 }2584 });2585 });2586 it('returns error when progress is malformed', function (done) {2587 helper.request2588 .put('/projects/progress')2589 .set('apiKey', config.apiKey)2590 .set('token', managerObject.token)2591 .send({2592 projectid: String(testProject._id),2593 progress: 'qwe',2594 })2595 .expect(400, (err, res) => {2596 if (err) return done(err);2597 try {2598 const json = JSON.parse(res.text);2599 test.object(json)2600 .hasProperty('type', 'VALIDATION_ERROR');2601 done();2602 } catch (error) {2603 done(error);2604 }2605 });2606 });2607 it('returns error when progress is out of range', function (done) {2608 helper.request2609 .put('/projects/progress')2610 .set('apiKey', config.apiKey)2611 .set('token', managerObject.token)2612 .send({2613 projectid: String(testProject._id),2614 progress: '101',2615 })2616 .expect(400, (err, res) => {2617 if (err) return done(err);2618 try {2619 const json = JSON.parse(res.text);2620 test.object(json)2621 .hasProperty('type', 'VALIDATION_ERROR');2622 done();2623 } catch (error) {2624 done(error);2625 }2626 });2627 });2628 it('disable progress for project as manager', function (done) {2629 helper.request2630 .put('/projects')2631 .set('apiKey', config.apiKey)2632 .set('token', managerObject.token)2633 .send({2634 projectid: String(testProject._id),2635 progressEnabled: false,2636 title: 'Should work too',2637 })2638 .expect(200, (err, res) => {2639 if (err) return done(err);2640 try {2641 const json = JSON.parse(res.text);2642 test2643 .object(json)2644 .hasProperty('progressEnabled', false);2645 done();2646 } catch (error) {2647 done(error);2648 }2649 });2650 });2651 it('returns error when trying to change progress as manager while progress disabled', function (done) {2652 helper.request2653 .put('/projects/progress')2654 .set('apiKey', config.apiKey)2655 .set('token', managerObject.token)2656 .send({2657 projectid: String(testProject._id),2658 progress: '1',2659 })2660 .expect(403, (err, res) => {2661 if (err) return done(err);2662 try {2663 const json = JSON.parse(res.text);2664 test.object(json)2665 .hasProperty('type', 'PROGRESS_DISABLED_ERROR');2666 done();2667 } catch (error) {2668 done(error);2669 }2670 });2671 });2672 it('Enabling progress for project again, as owner', function (done) {2673 helper.request2674 .put('/projects')2675 .set('apiKey', config.apiKey)2676 .set('token', user.token)2677 .send({2678 projectid: String(testProject._id),2679 progressEnabled: true,2680 title: 'Should work too',2681 })2682 .expect(200, (err, res) => {2683 if (err) return done(err);2684 try {2685 const json = JSON.parse(res.text);2686 test2687 .object(json)2688 .hasProperty('progressEnabled', true);2689 done();2690 } catch (error) {2691 done(error);2692 }2693 });2694 });2695 });2696 context('DELETE /projects', function () {2697 it('returns error when client tries to delete project', function (done) {2698 helper.request2699 .delete('/projects')2700 .set('apiKey', config.apiKey)2701 .set('token', secondManagerObject.token)2702 .send({2703 projectid: String(testProject._id),2704 })2705 .expect(403, (err, res) => {2706 if (err) return done(err);2707 try {2708 const json = JSON.parse(res.text);2709 test.object(json)2710 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');2711 done();2712 } catch (error) {2713 done(error);2714 }2715 });2716 });2717 it('returns error when manager tries to delete project', function (done) {2718 helper.request2719 .delete('/projects')2720 .set('apiKey', config.apiKey)2721 .set('token', managerObject.token)2722 .send({2723 projectid: String(testProject._id),2724 })2725 .expect(403, (err, res) => {2726 if (err) return done(err);2727 try {2728 const json = JSON.parse(res.text);2729 test.object(json)2730 .hasProperty('type', 'NOT_AUTHORIZED_ERROR');2731 done();2732 } catch (error) {2733 done(error);2734 }2735 });2736 });2737 it('successfully deletes project', function (done) {2738 helper.request2739 .delete('/projects')2740 .set('apiKey', config.apiKey)2741 .set('token', user.token)2742 .send({2743 projectid: String(testProject._id),2744 })2745 .expect(200, (err, res) => {2746 if (err) return done(err);2747 try {2748 const json = JSON.parse(res.text);2749 test.object(json)2750 .hasProperty('success', true);2751 done();2752 } catch (error) {2753 done(error);2754 }2755 });2756 });2757 });...

Full Screen

Full Screen

store.test.js

Source:store.test.js Github

copy

Full Screen

1const { wait } = require('../shared/promise');2const { getPath } = require('../shared/object');3const path = require('path');4const os = require('os');5const fs = require('fs');6const { Store, ensureProjectFile } = require('./store');7const {8 ProjectState,9 ProjectPage,10 ProgramPanelInfo,11 PanelResult,12 Encrypt,13 DatabaseConnectorInfo,14 ServerInfo,15} = require('../shared/state');16const { ensureSigningKey } = require('./secret');17const store = new Store();18const storeHandlers = store.getHandlers();19const makeProject = storeHandlers.filter(20 (r) => r.resource === 'makeProject'21)[0];22const updateConnector = storeHandlers.filter(23 (r) => r.resource === 'updateConnector'24)[0];25const updateServer = storeHandlers.filter(26 (r) => r.resource === 'updateServer'27)[0];28const updatePanel = storeHandlers.filter(29 (r) => r.resource === 'updatePanel'30)[0];31const deletePanel = storeHandlers.filter(32 (r) => r.resource === 'deletePanel'33)[0];34const updatePanelResults = storeHandlers.filter(35 (r) => r.resource === 'updatePanelResult'36)[0];37const updatePage = storeHandlers.filter((r) => r.resource === 'updatePage')[0];38const getProject = storeHandlers.filter((r) => r.resource === 'getProject')[0];39test('write project with encrypted secrets, read with nulled secrets', async () => {40 // Shouldn't be harmful even though it is potentially creating a new41 // real file. It's value is valid and wouldn't overwrite an existing42 // one. Just necessary to call so that in tests this is definitely43 // populated.44 ensureSigningKey();45 const testProject = new ProjectState();46 const testPage = new ProjectPage('My test page');47 testProject.pages = [testPage];48 const testPanel = new ProgramPanelInfo(testPage.id, { type: 'python' });49 testPage.panels = [testPanel];50 const testServer = new ServerInfo();51 const testServerPassword = 'taffy';52 testServer.password_encrypt = new Encrypt(testServerPassword);53 const testServerPassphrase = 'kewl';54 testServer.passphrase_encrypt = new Encrypt(testServerPassphrase);55 testProject.servers.push(testServer);56 const testDatabase = new DatabaseConnectorInfo();57 const testDatabasePassword = 'kevin';58 testDatabase.database.password_encrypt = new Encrypt(testDatabasePassword);59 testProject.connectors.push(testDatabase);60 const projectId = 'unittestproject';61 const projectPath = ensureProjectFile(projectId);62 expect(projectPath).toBe(63 path.join(os.homedir(), 'DataStationProjects', projectId + '.dsproj')64 );65 testProject.projectName = projectPath;66 // Delete and recreate it to be safe67 try {68 fs.unlinkSync(projectPath);69 } catch (e) {70 /* nothing */71 }72 ensureProjectFile(projectId);73 try {74 await makeProject.handler(null, { projectId });75 await updateServer.handler(projectId, {76 data: testServer,77 position: 0,78 insert: true,79 });80 await updateConnector.handler(projectId, {81 data: testDatabase,82 position: 0,83 insert: true,84 });85 await updatePage.handler(projectId, {86 data: { ...testPage },87 position: 0,88 insert: true,89 });90 await updatePanel.handler(projectId, {91 data: testPanel,92 position: 0,93 insert: true,94 });95 const onDisk = await getProject.handler(null, { projectId }, null, false);96 // Passwords are encrypted97 expect(onDisk.servers[0].password_encrypt.value.length).not.toBe(0);98 expect(onDisk.servers[0].password_encrypt.value).not.toBe(99 testServerPassword100 );101 expect(onDisk.servers[0].password_encrypt.encrypted).toBe(true);102 expect(onDisk.servers[0].passphrase_encrypt.value.length).not.toBe(0);103 expect(onDisk.servers[0].passphrase_encrypt.value).not.toBe(104 testServerPassphrase105 );106 expect(onDisk.servers[0].passphrase_encrypt.encrypted).toBe(true);107 expect(108 onDisk.connectors[0].database.password_encrypt.value.length109 ).not.toBe(0);110 expect(onDisk.connectors[0].database.password_encrypt.value).not.toBe(111 testDatabasePassword112 );113 expect(onDisk.connectors[0].database.password_encrypt.encrypted).toBe(true);114 // Passwords come back as null115 const readProject = await getProject.handler(null, { projectId });116 readProject.id = testProject.id; // id is generated newly on every instantiation which is ok117 // Time objects don't compare well118 readProject.pages[0].panels[0].lastEdited =119 testProject.pages[0].panels[0].lastEdited = null;120 testProject.pages[0].panels[0].defaultModified = false;121 // Super weird but it fails saying "serializes to the same string" even when you use spread operator.122 expect(JSON.stringify(readProject)).toStrictEqual(123 JSON.stringify(ProjectState.fromJSON(testProject))124 );125 } finally {126 try {127 fs.unlinkSync(projectPath);128 } catch (e) {129 console.error(e);130 }131 }132});133test('newly created project is saved correctly', async () => {134 const testProject = new ProjectState();135 testProject.projectName = ensureProjectFile(testProject.id);136 // Delete and recreate it to be safe137 try {138 fs.unlinkSync(testProject.projectName);139 } catch (e) {140 /* nothing */141 }142 ensureProjectFile(testProject.projectName);143 try {144 await makeProject.handler(null, { projectId: testProject.projectName });145 const read = await getProject.handler(null, {146 projectId: testProject.projectName,147 });148 read.id = testProject.id; // id is generated newly on every instantiation which is ok149 // Super weird but it fails saying "serializes to the same string" even when you use spread operator.150 expect(JSON.stringify(read)).toEqual(JSON.stringify(testProject));151 } finally {152 const projectPath = ensureProjectFile(testProject.projectName);153 try {154 fs.unlinkSync(projectPath);155 } catch (e) {156 console.error(e);157 }158 }159});160test('updates works correctly', async () => {161 const testProject = new ProjectState();162 testProject.projectName = ensureProjectFile(testProject.id);163 // Delete and recreate it to be safe164 try {165 fs.unlinkSync(testProject.projectName);166 } catch (e) {167 /* nothing */168 }169 ensureProjectFile(testProject.projectName);170 const testPage = new ProjectPage('My test page');171 testProject.pages = [testPage];172 const testPanel = new ProgramPanelInfo(testPage.id, { type: 'python' });173 testPage.panels = [testPanel];174 const projectId = testProject.projectName;175 const testServer = new ServerInfo();176 const testServerPassword = 'taffy';177 testServer.password_encrypt = new Encrypt(testServerPassword);178 const testServerPassphrase = 'kewl';179 testServer.passphrase_encrypt = new Encrypt(testServerPassphrase);180 testProject.servers.push(testServer);181 const testDatabase = new DatabaseConnectorInfo();182 const testDatabasePassword = 'kevin';183 testDatabase.database.password_encrypt = new Encrypt(testDatabasePassword);184 testProject.connectors.push(testDatabase);185 try {186 await makeProject.handler(null, { projectId });187 // Add the server188 await updateServer.handler(projectId, {189 data: testServer,190 position: 0,191 insert: true,192 });193 // Add the database194 await updateConnector.handler(projectId, {195 data: testDatabase,196 position: 0,197 insert: true,198 });199 // Add the page200 await updatePage.handler(projectId, {201 data: testPage,202 position: 0,203 insert: true,204 });205 // Add the panel206 await updatePanel.handler(projectId, {207 data: { ...testPanel },208 position: 0,209 insert: true,210 });211 // Update the panel212 testPanel.content = 'DM_getPanel(1)';213 await updatePanel.handler(projectId, {214 data: { ...testPanel },215 position: 0,216 insert: false,217 });218 // Update the page219 testPage.name = 'A better name';220 await updatePage.handler(projectId, {221 data: testPage,222 position: 0,223 insert: false,224 });225 // Update the server226 testServer.name = 'A great server';227 await updateServer.handler(projectId, {228 data: testServer,229 position: 0,230 insert: false,231 });232 // Update the database233 testDatabase.name = 'A great database';234 await updateConnector.handler(projectId, {235 data: testDatabase,236 position: 0,237 insert: false,238 });239 const read = await getProject.handler(null, {240 projectId: testProject.projectName,241 });242 expect(read.pages[0].name).toBe('A better name');243 expect(read.servers[0].name).toBe('A great server');244 expect(read.connectors[0].name).toBe('A great database');245 expect(read.pages[0].panels[0].lastEdited > testPanel.lastEdited);246 read.pages[0].panels[0].lastEdited = testPanel.lastEdited = null;247 testPanel.defaultModified = true;248 expect(read.pages[0].panels[0]).toStrictEqual(testPanel);249 } finally {250 const projectPath = ensureProjectFile(testProject.projectName);251 try {252 fs.unlinkSync(projectPath);253 } catch (e) {254 console.error(e);255 }256 }257});258test('panel reordering works correctly', async () => {259 const testProject = new ProjectState();260 testProject.projectName = ensureProjectFile(testProject.id);261 // Delete and recreate it to be safe262 try {263 fs.unlinkSync(testProject.projectName);264 } catch (e) {265 /* nothing */266 }267 ensureProjectFile(testProject.projectName);268 const testPage = new ProjectPage('My test page');269 testProject.pages = [testPage];270 const testPanel1 = new ProgramPanelInfo(testPage.id, { type: 'python' });271 const testPanel2 = new ProgramPanelInfo(testPage.id, { type: 'javascript' });272 testPage.panels = [testPanel1, testPanel2];273 const projectId = testProject.projectName;274 try {275 await makeProject.handler(null, { projectId });276 // Add the page277 await updatePage.handler(projectId, {278 data: testPage,279 position: 0,280 insert: true,281 });282 // Add the panels283 await updatePanel.handler(projectId, {284 data: { ...testPanel1 },285 position: 0,286 insert: true,287 });288 await updatePanel.handler(projectId, {289 data: { ...testPanel2 },290 position: 1,291 insert: true,292 });293 // Move 2 to 1294 await updatePanel.handler(projectId, {295 data: { ...testPanel2 },296 position: 0,297 insert: false,298 panelPositions: [testPanel2.id, testPanel1.id],299 });300 const read = await getProject.handler(null, {301 projectId,302 });303 // Don't try to compare lastEdited304 [...read.pages[0].panels, testPanel2, testPanel1].forEach((p) => {305 p.lastEdited = null;306 });307 testPanel2.defaultModified = true;308 // Reversed309 expect(read.pages[0].panels).toStrictEqual([testPanel2, testPanel1]);310 } finally {311 const projectPath = ensureProjectFile(testProject.projectName);312 try {313 fs.unlinkSync(projectPath);314 } catch (e) {315 console.error(e);316 }317 }318});319test('panel delete deletes the result', async () => {320 const testProject = new ProjectState();321 testProject.projectName = ensureProjectFile(testProject.id);322 // Delete and recreate it to be safe323 try {324 fs.unlinkSync(testProject.projectName);325 } catch (e) {326 /* nothing */327 }328 ensureProjectFile(testProject.projectName);329 const testPage = new ProjectPage('My test page');330 testProject.pages = [testPage];331 const testPanel = new ProgramPanelInfo(testPage.id, { type: 'python' });332 testPage.panels = [testPanel];333 const testResult = new PanelResult();334 const projectId = testProject.projectName;335 try {336 await makeProject.handler(null, { projectId });337 await updatePage.handler(projectId, {338 data: testPage,339 position: 0,340 insert: true,341 });342 await updatePanel.handler(projectId, {343 data: testPanel,344 position: 0,345 insert: true,346 });347 await updatePanelResults.handler(projectId, {348 data: testResult,349 panelId: testPanel.id,350 });351 await deletePanel.handler(projectId, {352 id: testPanel.id,353 });354 for (const table of ['ds_panel', 'ds_result']) {355 const stmt = store356 .getConnection(projectId)357 .prepare('SELECT * FROM ' + table);358 const res = stmt.all();359 expect(res.length).toBe(0);360 }361 } finally {362 const projectPath = ensureProjectFile(testProject.projectName);363 try {364 fs.unlinkSync(projectPath);365 } catch (e) {366 console.error(e);367 }368 }369});370test('migrates old JSON project', async () => {371 const testProject = new ProjectState();372 testProject.projectName = ensureProjectFile(testProject.id);373 // Delete and recreate it to be safe374 try {375 fs.unlinkSync(testProject.projectName);376 } catch (e) {377 /* nothing */378 }379 ensureProjectFile(testProject.projectName);380 const testPage = new ProjectPage('My test page');381 testProject.pages = [testPage];382 const testPanel = new ProgramPanelInfo(testPage.id, { type: 'python' });383 testPage.panels = [testPanel];384 const testResult = new PanelResult();385 testPanel.resultMeta = testResult;386 fs.writeFileSync(testProject.projectName, JSON.stringify(testProject));387 try {388 // Get project to trigger migration389 const result = await getProject.handler(null, {390 projectId: testProject.projectName,391 });392 // .bak file has been written correctly393 expect(fs.readFileSync(testProject.projectName + '.bak').toString()).toBe(394 JSON.stringify(testProject)395 );396 // Rewritten file is SQLite397 expect(store.isSQLiteFile(testProject.projectName)).toBe(true);398 // It's ok that these change399 result.id = testProject.id;400 result.pages[0].panels[0].lastEdited = testPanel.lastEdited = null;401 // But otherwise correctly filled out402 expect(JSON.stringify(testProject)).toBe(JSON.stringify(result));403 } finally {404 const projectPath = ensureProjectFile(testProject.projectName);405 try {406 fs.unlinkSync(projectPath);407 } catch (e) {408 console.error(e);409 }410 const projectBakPath = ensureProjectFile(testProject.projectName + '.bak');411 try {412 fs.unlinkSync(projectBakPath);413 } catch (e) {414 console.error(e);415 }416 }...

Full Screen

Full Screen

documentDAO.test.js

Source:documentDAO.test.js Github

copy

Full Screen

1const projectDAO = require('../../../dao/projectDAO');2const documentDAO = require('../../../dao/documentDAO');3const constants = require('../../../helpers/constants');4const project = require('../../../helpers/models/project');5const fs = require('fs');6const MinioController = require('../../../helpers/minio');7require('../../test_helper');8require('../../../helpers/models/audit');9require('../../../helpers/models/document');10describe('API Testing - Documents DAO', () => {11 let testProject = new project();12 testProject.CEAAInvolvement = null; //oid13 testProject.CELead = '';14 testProject.CELeadEmail = '';15 testProject.CELeadPhone = '';16 testProject.centroid = [ 123, 49 ];17 testProject.description = 'Test Project, please delete me';18 testProject.eacDecision = null; // oid19 testProject.location = 'Right behind you';20 testProject.name = 'An excellent test project';21 testProject.projectLeadId = null; // oid22 testProject.projectLead = '';23 testProject.projectLeadEmail = '';24 testProject.projectLeadPhone = '';25 testProject.proponent = null; // oid26 testProject.region = 'Lower Mainland';27 testProject.responsibleEPDId = null; // oid28 testProject.responsibleEPD = '';29 testProject.responsibleEPDEmail = '';30 testProject.responsibleEPDPhone = '';31 testProject.type = 'Energy-Petroleum & Natural Gas';32 testProject.legislation = '2018 Environmental Assessment Act';33 testProject.legislationYear = 2018;34 testProject.nameSearchTerms = ['Test'];35 testProject.addedBy = '';36 testProject.build = 'modification';37 testProject.CEAALink = '';38 testProject.code = '';39 testProject.commodity = '';40 testProject.currentPhaseName = null; // oid41 testProject.phaseHistory = '';42 testProject.dateAdded = '';43 testProject.dateCommentsClosed = '';44 testProject.dateCommentsOpen = '';45 testProject.dateUpdated = '';46 testProject.decisionDate = null;47 testProject.duration = '';48 // TODO: directoryStructure49 testProject.eaoMember = '';50 testProject.fedElecDist = '';51 // TODO: intake52 testProject.intake = '';53 testProject.isTermsAgreed = false;54 testProject.overallProgress = 0;55 testProject.primaryContact = '';56 testProject.proMember = '';57 testProject.provElecDist = '';58 testProject.sector = 'Energy Storage Facilities';59 testProject.shortName = '';60 testProject.status = 'Early Engagement';61 testProject.substitution = false;62 // TODO: New Stuff?63 testProject.eaStatusDate = '';64 testProject.eaStatus = '';65 testProject.projectStatusDate = '';66 testProject.substantiallyDate = '';67 testProject.substantially = false;68 testProject.disputeDate = '';69 testProject.dispute = false;70 testProject.activeDate = '';71 testProject.activeStatus = '';72 // Project Review Data73 testProject.review180Start = null;74 testProject.review45Start = null;75 testProject.reviewSuspensions = {};76 testProject.reviewExtensions = {};77 testProject.projLead = null; // oid78 testProject.execProjectDirector = null; // oid79 testProject.complianceLead = null; // oid80 testProject.groups = null;81 test('Document CRUD tests', async () => {82 // create a dummy project83 let project = await projectDAO.createProject('Test User', testProject);84 // let comment = Waiting for Comment v2 controller and handlers85 // get a couple of dummy file handles for upload86 //const publicFile = new File(['(⌐□_□)'], 'testPublicFile.png', { type: 'image/png' })87 const secureFileBuffer = fs.readFileSync('./api/test/tests/test_docs/Oahu.png');88 let secureFile =89 {90 buffer: secureFileBuffer,91 encoding: '7bit',92 fieldname: 'upfile',93 mimetype: 'image/png',94 originalname: 'Oahu.png',95 size: 1234596 };97 //let publicDocumentDetails =98 //{99 // originalName : 'testPublicFile',100 // displayName : fileName,101 // documentSource : 'COMMENT',102 // documentAuthor : 'Johnny Awesome',103 // documentAuthorType : null,104 //};105 let secureDocumentDetails =106 {107 originalName : 'testSecureFile',108 fileName : 'testSecureFile',109 displayName : 'testSecureFile',110 legislation : '2018',111 documentSource : 'PROJECT',112 eaoStatus : 'Rejected',113 publish : false,114 milestone : null,115 type : null,116 documentAuthor : 'Johnny Awesome',117 documentAuthorType : null,118 dateUploaded : new Date(),119 datePosted : new Date(),120 description : 'Testing, testing, 1, 2, 3',121 projectPhase : null122 };123 // create Public ? Waiting for comment v2 enpoints124 // let pubDocument = await documentDAO.createDocument('Test User', null, comment, ?, publicDocumentDetails, true);125 // create Secure126 let secureDocument = await documentDAO.createDocument('Test User', project._id, null, secureFile, 'png', secureDocumentDetails, false);127 expect(secureDocument).not.toEqual(null);128 expect(secureDocument.documentFileName).toEqual('testSecureFile');129 // Update130 secureDocument.documentFileName = 'Updated test file name';131 secureDocument.internalExt = 'png';132 let updatedDocument = await documentDAO.updateDocument('Test User', secureDocument, secureDocument.project, secureFile, secureDocument);133 expect(updatedDocument).not.toEqual(null);134 expect(updatedDocument.documentFileName).toEqual('Updated test file name');135 // publish136 updatedDocument = await documentDAO.publishDocument('Test User', updatedDocument);137 expect(updatedDocument).not.toEqual(null);138 expect(updatedDocument.eaoStatus).toEqual('Published');139 // fetch140 let docResults = await documentDAO.fetchDocuments(0, 1000, null, null, null, project._id, [], constants.PUBLIC_ROLES);141 expect(docResults).not.toEqual(null);142 expect(docResults[0].searchResults.length).toEqual(1);143 expect(docResults[0].searchResults[0]._id).toEqual(updatedDocument._id);144 // unpublish145 updatedDocument = await documentDAO.unPublishDocument('Test User', updatedDocument);146 expect(updatedDocument).not.toEqual(null);147 expect(updatedDocument.eaoStatus).toEqual('Rejected');148 docResults = await documentDAO.fetchDocuments(0, 1000, null, null, null, project._id, [], constants.PUBLIC_ROLES);149 expect(docResults).not.toEqual(null);150 expect(docResults[0].searchResults.length).toEqual(0);151 docResults = await documentDAO.fetchDocuments(0, 1000, null, null, null, project._id, [], constants.SECURE_ROLES);152 expect(docResults).not.toEqual(null);153 expect(docResults[0].searchResults.length).toEqual(1);154 expect(docResults[0].searchResults[0]._id).toEqual(updatedDocument._id);155 // feature156 updatedDocument = await documentDAO.featureDocument(updatedDocument, project);157 expect(updatedDocument).not.toEqual(null);158 expect(updatedDocument.isFeatured).toEqual(true);159 // unfeature160 updatedDocument = await documentDAO.unfeatureDocument(updatedDocument, project);161 expect(updatedDocument).not.toEqual(null);162 expect(updatedDocument.isFeatured).toEqual(false);163 // download (don't need on a mock, so how to test this?)164 let meta = await documentDAO.downloadDocumentGetMeta(constants.SECURE_ROLES, 'Test User', updatedDocument, 'good_name');165 expect(meta).not.toEqual(null);166 expect(meta.fileName).toEqual('good_name.png');167 // delete168 updatedDocument = await documentDAO.deleteDocument('Test User', updatedDocument);169 expect(updatedDocument).not.toEqual(null);170 //pubDocument = await documentDAO.deleteDocument('Test User', pubDocument);171 // delete the temp documents from Minio as well!172 // public173 //MinioController.deleteDocument(MinioController.BUCKETS.DOCUMENTS_BUCKET, pubDocument.project, pubDocument.internalURL);174 // secure175 MinioController.deleteDocument(MinioController.BUCKETS.DOCUMENTS_BUCKET, updatedDocument.project, updatedDocument.internalURL);176 });...

Full Screen

Full Screen

projectDAO.test.js

Source:projectDAO.test.js Github

copy

Full Screen

1const projectDAO = require('../../../dao/projectDAO');2const projectGroupDAO = require('../../../dao/projectGroupDAO');3const pinDAO = require('../../../dao/pinDAO');4const constants = require('../../../helpers/constants');5const projectControllerV1 = require('../../../controllers/project');6const project = require('../../../helpers/models/project');7const test_helper = require('../../test_helper');8require('../../../helpers/models/audit');9require('../../../helpers/models/group');10require('../../../helpers/models/cacUser');11describe('API Testing - Project DAO', () => {12 let testProject = new project();13 testProject.CEAAInvolvement = null; //oid14 testProject.CELead = '';15 testProject.CELeadEmail = '';16 testProject.CELeadPhone = '';17 testProject.centroid = [ 123, 49 ];18 testProject.description = 'Test Project, please delete me';19 testProject.eacDecision = null; // oid20 testProject.location = 'Right behind you';21 testProject.name = 'An excellent test project';22 testProject.projectLeadId = null; // oid23 testProject.projectLead = '';24 testProject.projectLeadEmail = '';25 testProject.projectLeadPhone = '';26 testProject.proponent = null; // oid27 testProject.region = 'Lower Mainland';28 testProject.responsibleEPDId = null; // oid29 testProject.responsibleEPD = '';30 testProject.responsibleEPDEmail = '';31 testProject.responsibleEPDPhone = '';32 testProject.type = 'Energy-Petroleum & Natural Gas';33 testProject.legislation = '2018 Environmental Assessment Act';34 testProject.legislationYear = 2018;35 testProject.nameSearchTerms = ['Test'];36 testProject.addedBy = '';37 testProject.build = 'modification';38 testProject.CEAALink = '';39 testProject.code = '';40 testProject.commodity = '';41 testProject.currentPhaseName = null; // oid42 testProject.phaseHistory = '';43 testProject.dateAdded = '';44 testProject.dateCommentsClosed = '';45 testProject.dateCommentsOpen = '';46 testProject.dateUpdated = '';47 testProject.decisionDate = null;48 testProject.duration = '';49 // TODO: directoryStructure50 testProject.eaoMember = '';51 testProject.fedElecDist = '';52 // TODO: intake53 testProject.intake = {54 investment: '',55 notes: ''56 };57 testProject.isTermsAgreed = false;58 testProject.overallProgress = 0;59 testProject.primaryContact = '';60 testProject.proMember = '';61 testProject.provElecDist = '';62 testProject.sector = 'Energy Storage Facilities';63 testProject.shortName = '';64 testProject.status = 'Early Engagement';65 testProject.substitution = false;66 // TODO: New Stuff?67 testProject.eaStatusDate = '';68 testProject.eaStatus = '';69 testProject.projectStatusDate = '';70 testProject.substantiallyDate = '';71 testProject.substantially = false;72 testProject.disputeDate = '';73 testProject.dispute = false;74 testProject.activeDate = '';75 testProject.activeStatus = '';76 // Project Review Data77 testProject.review180Start = null;78 testProject.review45Start = null;79 testProject.reviewSuspensions = {};80 testProject.reviewExtensions = {};81 testProject.projLead = null; // oid82 testProject.execProjectDirector = null; // oid83 testProject.complianceLead = null; // oid84 testProject.groups = null;85 test('Project CRUD tests', async () => {86 // Create87 let createdProject = await projectDAO.createProject('Test User', testProject);88 expect(createdProject.id).not.toEqual(null);89 let loadedProject = await projectDAO.getProject(constants.SECURE_ROLES, createdProject._id);90 expect(loadedProject).not.toEqual(null);91 expect(loadedProject._id).toEqual(createdProject._id);92 loadedProject.shortName = 'Changed Short Name!';93 let updatedProject = await projectDAO.updateProject('Test User', createdProject, loadedProject);94 expect(updatedProject).not.toEqual(null);95 expect(updatedProject._id).toEqual(createdProject._id);96 let deletedProject = await projectDAO.deleteProject('Test User', createdProject, updatedProject);97 expect(deletedProject).not.toEqual(null);98 expect(deletedProject._id).toEqual(createdProject._id);99 });100 test('Project Pin tests', async () => {101 let createdProject = await projectDAO.createProject('Test User', testProject);102 expect(createdProject.id).not.toEqual(null);103 let pins = { value: [123, 456, 789]};104 let result = await pinDAO.createPin('Test User', createdProject, pins);105 expect(result).not.toEqual(null);106 expect(result.nModified).toBeGreaterThan(0);107 createdProject = await projectDAO.getProject(constants.SECURE_ROLES, createdProject._id);108 result = await pinDAO.publishPins('Test', createdProject);109 expect(result.nModified).toBeGreaterThan(0);110 createdProject = await projectDAO.getProject(constants.SECURE_ROLES, createdProject._id);111 result = await pinDAO.unPublishPins('Test', createdProject);112 expect(result.nModified).toBeGreaterThan(0);113 createdProject = await projectDAO.getProject(constants.SECURE_ROLES, createdProject._id);114 result = await pinDAO.deletePin('Test', createdProject.pins[2], createdProject);115 expect(result.nModified).toBeGreaterThan(0);116 result = await pinDAO.deletePin('Test', createdProject.pins[1], createdProject);117 expect(result.nModified).toBeGreaterThan(0);118 result = await pinDAO.deletePin('Test', createdProject.pins[0], createdProject);119 expect(result.nModified).toBeGreaterThan(0);120 createdProject = await projectDAO.getProject(constants.SECURE_ROLES, createdProject._id);121 expect(createdProject.pins.length).toEqual(0);122 });123 // ? Include group add members once the Users endpoints for v2 have been created124 test('Project Group tests', async () => {125 // Create126 let createdProject = await projectDAO.createProject('Test User', testProject);127 expect(createdProject.id).not.toEqual(null);128 let result = await projectGroupDAO.createGroup('Test', 'Test', createdProject);129 expect(result).not.toEqual(null);130 expect(result.project).toEqual(createdProject._id);131 expect(result.name).toEqual('Test');132 let editedGroup =133 {134 name: 'Edited Test',135 members: result.members,136 project: result.project,137 read: result.read,138 write: result.write,139 delete: result.delete,140 _schemaName: 'Group',141 _id: result._id,142 __v: result.__v,143 id: result.id144 };145 result = await projectGroupDAO.updateGroup('Test', editedGroup, result);146 expect(result).not.toEqual(null);147 expect(result.project).toEqual(createdProject._id);148 expect(result.name).toEqual('Edited Test');149 let fetchedResult = await projectGroupDAO.getGroup(result._id);150 expect(fetchedResult).not.toEqual(null);151 expect(fetchedResult).toMatchObject(result);152 result = await projectGroupDAO.deleteGroup('Test', fetchedResult, createdProject);153 result = await projectGroupDAO.getGroup(fetchedResult._id);154 expect(result).toEqual(null);155 });156 test('Project CAC SignUp tests', async () => {157 // Create158 let createdProject = await projectDAO.createProject('Test Project', testProject);159 expect(createdProject.id).not.toEqual(null);160 let res = {161 writeHead: function(code) {162 // 200 or fail163 expect(code).toEqual(200);164 },165 end: function (data) {166 // We should get a plain object back167 expect(typeof(JSON.parse(data))).toEqual('object');168 }169 };170 const formattedObj = {171 cac: {172 value:173 {174 name: 'Mark Lise',175 email: 'mark@digitalspace.ca',176 comment: 'I like tests!'177 }178 },179 projId: {180 value: '5ebaed0c516bac001aefe5aa'181 }182 };183 const paramsWithValues = test_helper.createSwaggerParams([], formattedObj);184 // fix this.185 await projectControllerV1.publicCACSignUp(paramsWithValues, res);186 });...

Full Screen

Full Screen

test-project.js

Source:test-project.js Github

copy

Full Screen

1var express = require('express');2var mongoose = require('mongoose');3var request = require('request');4var jwt = require('jwt-simple');5var middleware = require('./middleware');6var TestProject = mongoose.model('TestProject');7var TestSuite = mongoose.model('TestSuite');8var TestCase = mongoose.model('TestCase');9module.exports = function(app, passport) {10 //Get the projects11 app.get('/api/testProject', middleware.ensureAuthenticated, function(req, res) {12 TestProject.find({}, function(err, tp) {13 if(err){14 console.log(err);15 }16 else{17 if (tp) {18 res.send(tp);19 }else{20 return res.status(500).send({ message: 'Projects not found' });21 };22 }23 });24 });25 //Get the projects26 app.get('/api/testProject/:id', middleware.ensureAuthenticated, function(req, res) {27 TestProject.findOne({_id: req.params.id},function(err, tp) {28 if(err){29 console.log(err);30 }31 else{32 if (tp) {33 res.send(tp);34 }else{35 return res.status(500).send({ message: 'Project not found' });36 };37 }38 });39 });40 //add a new test project41 app.put('/api/testProject', middleware.ensureAuthenticated, function(req, res) {42 TestProject.findOne({ name: req.body.testProject.name }, function(err, tp) {43 if(err){44 console.log(err);45 }46 else{47 if (tp) {48 return res.status(500).send({ message: 'Project test already exists' });49 }else{50 var newTP = new TestProject({51 name: req.body.testProject.name,52 prefix: req.body.testProject.prefix,53 currentTcNumber: 1,54 priorities: req.body.testProject.priorities,55 status: req.body.testProject.status,56 description: req.body.testProject.description57 });58 newTP.save(function(err, tpjResult) {59 if (err) {60 res.status(500).send({ message: err.message });61 }62 tpjResult.tmTreeData = "[{label: '"+req.body.testProject.name+"', type: 'tpj', _id: '" + tpjResult._id + "', children: []}]";63 tpjResult.save(function(err, result) {64 if (err) {65 res.status(500).send({ message: err.message });66 }67 return res.send("succesfully saved");68 });69 });70 };71 }72 });73 });74 //update a field75 app.post('/api/testProject/:id', middleware.ensureAuthenticated, function(req, res) {76 TestProject.findOne({_id: req.params.id}, function(err, tp) {77 if(err){78 console.log(err);79 }80 else{81 if (!tp) {82 return res.status(500).send({ message: "Project test doesn't exists" });83 }else{84 //TODO for each field, if req.body.testProject.XXX is undefined, not replace!!85 tp.name = req.body.testProject.name;86 tp.prefix = req.body.testProject.prefix;87 tp.currentTcNumber = req.body.testProject.currentTcNumber;88 tp.priorities = req.body.testProject.priorities;89 tp.status = req.body.testProject.status;90 tp.description = req.body.testProject.description;91 tp.tmTreeData = req.body.testProject.tmTreeData;92 TestProject.findOneAndUpdate({_id:req.params.id}, tp, {upsert:true}, function(err, doc){93 if (err) res.status(500).send({ message: err.message });94 return res.send("succesfully saved");95 });96 };97 }98 });99 });100 //delete a test plan101 app.delete('/api/testProject/:id', middleware.ensureAuthenticated, function(req, res) {102 TestProject.findOne({_id: req.params.id}, function(err, tp) {103 if(err){104 console.log(err);105 }106 else{107 if (tp) {108 tp.remove(function(err, result) {109 if (err) {110 res.status(500).send({ message: err.message });111 }112 //delete all testSuites and testCase with tpjId === req.params.id113 TestSuite.find({tpjId: req.params.id}).remove().exec();114 TestCase.find({tpjId: req.params.id}).remove().exec();115 return res.send("succesfully deleted");116 });117 }else{118 return res.status(500).send({ message: "Project test doesn't exists" });119 };120 }121 });122 });...

Full Screen

Full Screen

file-system.spec.js

Source:file-system.spec.js Github

copy

Full Screen

1/* global describe it beforeEach afterEach */2import fileSystem from '../../src/project/file-system'3const testUser = 'tester'4const testProject = 'test'5// NOTE: Read/Write to Firebase tests skipped due to Error: PERMISSION_DENIED: Permission denied6describe('File System', () => {7 describe.skip('get()', () => {8 beforeEach(() =>9 fileSystem(testUser, testProject)10 .addFile('src/index.html', 'some file content')11 )12 afterEach(() =>13 fileSystem(testUser, testProject).file('src/index.html').remove()14 )15 it('gets project', () =>16 fileSystem(testUser, testProject)17 .get().should.eventually.have.property('src')18 )19 })20 describe.skip('addFile()', () => {21 it('exists', () =>22 fileSystem(testUser, testProject).should.respondTo('addFile')23 )24 it.skip('adds a file', () =>25 fileSystem(testUser, testProject)26 .addFile('src/index.html').should.eventually.have.property('meta')27 )28 it.skip('adds a file with content', () =>29 fileSystem(testUser, testProject)30 .addFile('src/index.html', 'some content')31 .should.eventually.have.property('meta')32 )33 })34 describe.skip('addFolder()', () => {35 it('exists', () =>36 fileSystem(testUser, testProject).should.respondTo('addFolder')37 )38 it('adds a folder', () =>39 fileSystem(testUser, testProject)40 .addFolder('something').should.eventually.have.property('meta')41 )42 })43 describe('clone', () => {44 it('exists', () =>45 fileSystem(testUser, testProject).should.respondTo('clone')46 )47 it.skip('clones one project into another', () =>48 fileSystem(testUser, testProject)49 .clone('test2', 'test').should.be.fullfilled50 )51 })52 describe('zip', () => {53 it('exists', () =>54 fileSystem(testUser, testProject).should.respondTo('zip')55 )56 it('has an alias "download"', () =>57 fileSystem(testUser, testProject).should.respondTo('download')58 )59 it.skip('downloads a zip file', () =>60 fileSystem(testUser, testProject)61 .zip().should.be.fullfilled62 )63 })64 describe('getUserColor', () => {65 it('exists', () =>66 fileSystem(testUser, testProject).should.respondTo('getUserColor')67 )68 it('returns a valid hex value', () =>69 fileSystem(testUser, testProject)70 .getUserColor().should.be.a.string71 )72 })73 describe('sub-models', () => {74 it('entity', () =>75 fileSystem(testUser, testProject).should.respondTo('entity')76 )77 it('file', () =>78 fileSystem(testUser, testProject).should.respondTo('file')79 )80 it('folder', () =>81 fileSystem(testUser, testProject).should.respondTo('folder')82 )83 })...

Full Screen

Full Screen

test-project.service.js

Source:test-project.service.js Github

copy

Full Screen

1'use strict';2/**3 * @ngdoc function4 * @name test4qaApp.service:DashboardService5 * @description6 * # DashboardService7 * Servie of the test4qaApp8 */9angular.module('test4qaApp')10.service('TestProjectCrudService', function(Restangular, $rootScope, $q) {11 //service to add a new testProject12 this.addTestProject = function($scope, testProject){13 var defered = $q.defer();14 var promise = defered.promise;15 Restangular.one("/api/testProject").customPUT({testProject: testProject}).then(function() {16 defered.resolve();17 },function (res) {18 defered.reject(res);19 });20 return promise;21 };22 //service to update a field of testProject23 this.updateTestProject = function(testProject){24 var defered = $q.defer();25 var promise = defered.promise;26 Restangular.one("/api/testProject/"+testProject._id).customPOST({testProject:testProject}).then(function() {27 defered.resolve();28 },function (res) {29 defered.reject(res);30 });31 return promise;32 };33 //Service to update only tmTreeData of testProject for a new TS.34 this.updateTmTreeDataTestProject = function(id, tmTreeData){35 var defered = $q.defer();36 var promise = defered.promise;37 Restangular.one("/api/testProject/"+id).get().then(function(testProject) {38 testProject.tmTreeData = tmTreeData;39 Restangular.one("/api/testProject/"+testProject._id).customPOST({testProject:testProject}).then(function() {40 defered.resolve();41 },function (res) {42 defered.reject(res);43 });44 },function (res) {45 defered.reject(res);46 });47 return promise;48 };49 //delete a testProject50 this.deleteTestProject = function($scope, id){51 var defered = $q.defer();52 var promise = defered.promise;53 Restangular.one("/api/testProject/"+id).remove().then(function() {54 defered.resolve();55 },function (res) {56 defered.reject(res);57 });58 return promise;59 };60 //Return all test projects61 this.getAllProjects = function($scope){62 var defered = $q.defer();63 var promise = defered.promise;64 Restangular.all("/api/testProject").getList().then(function(testProjects) {65 defered.resolve(testProjects);66 },function (res) {67 defered.reject(res);68 });69 return promise;70 };71 //Return test project72 this.getTestProject = function(id){73 var defered = $q.defer();74 var promise = defered.promise;75 Restangular.one("/api/testProject/"+id).get().then(function(testProject) {76 defered.resolve(testProject);77 },function (res) {78 defered.reject(res);79 });80 return promise;81 };...

Full Screen

Full Screen

styles.js

Source:styles.js Github

copy

Full Screen

1import * as style0 from "C:/d/repo/widgets-resources-cn/testProject/themesource/communitycommons/native/main";2import * as style1 from "C:/d/repo/widgets-resources-cn/testProject/themesource/nanoflowcommons/native/main";3import * as style2 from "C:/d/repo/widgets-resources-cn/testProject/themesource/webactions/native/main";4import * as style3 from "C:/d/repo/widgets-resources-cn/testProject/themesource/atlas_core/native/main";5import * as style4 from "C:/d/repo/widgets-resources-cn/testProject/themesource/myfirstmodule/native/main";6import * as style5 from "C:/d/repo/widgets-resources-cn/testProject/themesource/antmenu/native/main";7import * as style6 from "C:/d/repo/widgets-resources-cn/testProject/themesource/anttree/native/main";8import * as style7 from "C:/d/repo/widgets-resources-cn/testProject/themesource/antselect/native/main";9import * as style8 from "C:/d/repo/widgets-resources-cn/testProject/themesource/anttable/native/main";10import * as style9 from "C:/d/repo/widgets-resources-cn/testProject/themesource/unity/native/main";11import * as style10 from "C:/d/repo/widgets-resources-cn/testProject/themesource/barcodescanner/native/main";12import * as style11 from "C:/d/repo/widgets-resources-cn/testProject/themesource/fileviewer/native/main";13import * as style12 from "C:/d/repo/widgets-resources-cn/testProject/themesource/anticon/native/main";14import * as style13 from "C:/d/repo/widgets-resources-cn/testProject/themesource/amap/native/main";15import * as style14 from "C:/d/repo/widgets-resources-cn/testProject/themesource/playground/native/main";16import * as style15 from "C:/d/repo/widgets-resources-cn/testProject/themesource/graph/native/main";17import * as style16 from "C:/d/repo/widgets-resources-cn/testProject/theme/native/main";18import { flatten } from "mendix/native";...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9async function testProject() {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({path: 'example.png'});13 await browser.close();14}15module.exports = {16}17const puppeteer = require('./testProject');18puppeteer.testProject();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({4 });5 const page = await browser.newPage();6 await page.screenshot({path: 'example.png'});7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1testProject();2module.exports = async function testProject() {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7};

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const testProject = require('testproject-sdk');3const driver = testProject.OpenBrowser();4const browser = await puppeteer.connect({ browserWSEndpoint: driver.wsEndpoint() });5await browser.close();6[Apache License 2.0](

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful