Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. /// <reference path="../../typings/tsd.d.ts" />
  2. import domain = require('../src/dao/domain');
  3. import CameraMapper = require('../src/dao/mapper/camera/index');
  4. import repository = require('../src/dao/repository/index')
  5. import mongo = require('../src/dao/adapter/mongodb');
  6. import generators = require('./generators')
  7. import should = require('should');
  8. import _ = require('lodash')
  9. import mt = require('mocha-testcheck')
  10. import testcheck = require('testcheck')
  11. import Promise = require('bluebird')
  12.  
  13. mt.install(global);
  14. var persist = should;
  15.  
  16. describe("Mapper", () => {
  17.  
  18. describe("Camera Mapper", () => {
  19.  
  20. global.check.it('Given a camera object, map it to JSON, and then map it back to an object, and still be the same', { times: 10 }, [generators.genCamera], (camera) => {
  21. var mapper = CameraMapper.getCurrentVersion()
  22. var mappedBackAndForth = mapper.mapToModel(mapper.mapFromModel(camera))
  23. mappedBackAndForth.should.eql(camera)
  24. });
  25.  
  26. });
  27. })
  28.  
  29. describe("Repository", () => {
  30.  
  31. describe("Camera Repository", () => {
  32.  
  33. var cameraRepo = repository.getCameraRepository()
  34.  
  35. it("Should be able to insert a camera and retrieve same camera", (done) => {
  36.  
  37. var cameras = testcheck.sample(generators.genCamera, { times: 100 })
  38.  
  39. return Promise.map(cameras, (camera) => {
  40. return cameraRepo.save(camera).then((insertConfirmation) => {
  41. return insertConfirmation.getModels()[0]
  42. })
  43. .then((insertedCamera) => {
  44. should.exist(insertedCamera)
  45. var builder = new mongo.MongoQueryBuilder().where({ _id: insertedCamera.id });
  46. return cameraRepo.findOne(builder).then((found) => {
  47. var foundCamera = found[0]
  48. should.exist(foundCamera)
  49. foundCamera.should.eql(camera)
  50. })
  51. })
  52. })
  53. .then(() => { done() })
  54.  
  55. })
  56.  
  57. })
  58. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement