Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <reference path="../../typings/tsd.d.ts" />
- import domain = require('../src/dao/domain');
- import CameraMapper = require('../src/dao/mapper/camera/index');
- import repository = require('../src/dao/repository/index')
- import mongo = require('../src/dao/adapter/mongodb');
- import generators = require('./generators')
- import should = require('should');
- import _ = require('lodash')
- import mt = require('mocha-testcheck')
- import testcheck = require('testcheck')
- import Promise = require('bluebird')
- mt.install(global);
- var persist = should;
- describe("Mapper", () => {
- describe("Camera Mapper", () => {
- 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) => {
- var mapper = CameraMapper.getCurrentVersion()
- var mappedBackAndForth = mapper.mapToModel(mapper.mapFromModel(camera))
- mappedBackAndForth.should.eql(camera)
- });
- });
- })
- describe("Repository", () => {
- describe("Camera Repository", () => {
- var cameraRepo = repository.getCameraRepository()
- it("Should be able to insert a camera and retrieve same camera", (done) => {
- var cameras = testcheck.sample(generators.genCamera, { times: 100 })
- return Promise.map(cameras, (camera) => {
- return cameraRepo.save(camera).then((insertConfirmation) => {
- return insertConfirmation.getModels()[0]
- })
- .then((insertedCamera) => {
- should.exist(insertedCamera)
- var builder = new mongo.MongoQueryBuilder().where({ _id: insertedCamera.id });
- return cameraRepo.findOne(builder).then((found) => {
- var foundCamera = found[0]
- should.exist(foundCamera)
- foundCamera.should.eql(camera)
- })
- })
- })
- .then(() => { done() })
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement