Created
January 27, 2015 02:23
-
-
Save dbousamra/12dd1e00a9010bd81f05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <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() }) | |
| }) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment