Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2.  
  3. const Code = require('code')
  4. const Lab = require('lab')
  5. const lab = exports.lab = Lab.script()
  6.  
  7. var mongoose = require('mongoose');
  8. var mockgoose = require('mockgoose');
  9.  
  10. mockgoose(mongoose);
  11.  
  12. const suite = lab.suite
  13. const it = lab.test
  14. const before = lab.before
  15. const describe = lab.experiment
  16. const after = lab.after
  17. const expect = Code.expect
  18. const beforeEach = lab.beforeEach
  19. //const proxyquire = require('proxyquire')
  20. const sinon = require('sinon')
  21.  
  22. const partitionData = {
  23.     //cname: 'TESTER',
  24.     description: 'asdf',
  25.     status: true,
  26.     fields: [
  27.         {
  28.             name: 'Hostname',
  29.             type: 'string',
  30.             description: 'Server hostname (FQDN)',
  31.             primary: true,
  32.             visible: true,
  33.             required: true,
  34.             unique: true,
  35.             placeholder: 'server.domain.tld'
  36.  
  37.         },
  38.         {
  39.             name: 'Description',
  40.             type: 'text',
  41.             description: 'Description of server',
  42.             visible: true,
  43.             required: false,
  44.             unique: false,
  45.             placeholder: 'Server description'
  46.         },
  47.         {
  48.             name: 'Monitoring',
  49.             type: 'boolean',
  50.             description: 'Monitoring status of server',
  51.             visible: true,
  52.             default: true
  53.         }
  54.     ]
  55. }
  56.  
  57. before(function(done) {
  58.     mongoose.connect('mongodb://example.com/TestingDB', function(err) {
  59.         done(err)
  60.     })
  61. })
  62.  
  63. describe('Partition', function () {
  64.  
  65.     const Models = require('../../../dist/models')(mongoose)
  66.  
  67.     it("creates a new partition", function(done) {
  68.         let spy = sinon.spy()
  69.  
  70.         Models.Partition.createPartition( partitionData, (err, data) => {
  71.             if( err ){
  72.                 console.log('# ERROR:', err)
  73.                 return false
  74.             }
  75.  
  76.             console.log('# DATA:', data)
  77.         } )
  78.  
  79.         let Partition = Models.Partition.createPartition( partitionData, spy )
  80.  
  81.  
  82.         expect(spy.returned(sinon.match.same({name: 'TESTER'}))).to.equal( true )
  83.  
  84.  
  85.         done()
  86.     })
  87.  
  88. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement