diff --git a/client/camera/package.json b/client/camera/package.json index ca10b70..57d6940 100644 --- a/client/camera/package.json +++ b/client/camera/package.json @@ -9,7 +9,7 @@ "scripts": { "clean": "del coverage_report src/**/*.js src/**/*.map test/**/*.js test/**/*.map", "build": "tsc", - "test": "npm run clean && nyc mocha" + "test": "nyc mocha" }, "publishConfig": { "access": "public" @@ -29,7 +29,6 @@ "text" ], "report-dir": "coverage_report", - "check-coverage": true, "lines": 75, "functions": 100, "branches": 80 @@ -45,7 +44,13 @@ "proxyquire": "^1.8.0", "source-map-support": "^0.5.0", "ts-node": "^3.3.0", - "typescript": "^2.5.0" + "typescript": "^2.5.0", + "sinon": "^4.0.1", + "@types/sinon": "^2.3.3", + "@types/chai": "^4.0.3", + "chai": "^4.1.1", + "@types/chai-as-promised": "7.1.0", + "chai-as-promised": "^7.1.1" }, "dependencies": { "b64-to-blob": "^1.2.19" diff --git a/client/camera/src/Camera.ts b/client/camera/src/Camera.ts index 2fa971d..b43500e 100644 --- a/client/camera/src/Camera.ts +++ b/client/camera/src/Camera.ts @@ -18,8 +18,8 @@ export interface CaptureResponse { type optionsBuilderFn = (camera: any) => CameraOptions; export class Camera { - protected initPromise: Promise; - protected options: CameraOptions; + public options: CameraOptions; + public initPromise: Promise; constructor(optionsBuilderFunction?: optionsBuilderFn) { this.init(optionsBuilderFunction); diff --git a/client/camera/test/Camera-spec.ts b/client/camera/test/Camera-spec.ts new file mode 100644 index 0000000..d91c7aa --- /dev/null +++ b/client/camera/test/Camera-spec.ts @@ -0,0 +1,57 @@ +import * as Promise from 'bluebird'; +import { expect } from 'chai'; +import * as chai from 'chai'; +import * as chaiAsPromised from 'chai-as-promised'; +import * as sinon from 'sinon'; +import { buildCameraOptions } from '../src/buildCameraOptions'; +import { Camera } from '../src/Camera'; +import { mockCordovaCamera } from './mocks/camera'; +import { resolveLocalFileSystemURL } from './mocks/file'; + +declare var global: any; + +chai.use(chaiAsPromised); + +describe('Camera', function() { + const subject = new Camera(function() { + return { quality: 80 }; + }); + + describe('init', function() { + it('should take a function to partially supply options', function() { + return expect(subject.initPromise).to.eventually.have.property('quality', 80); + }); + }); + describe('cleanup', function() { + it('should call the cordova cleanup function', function() { + return subject.cleanup().then(function() { + sinon.assert.called(mockCordovaCamera.cleanup); + }); + }); + }); + describe('capture', function() { + it('return a local uri when successful', function() { + return subject.capture().then(result => { + expect(result).to.deep.equal({ + type: 'uri', + value: 'some-uri' + }); + sinon.assert.called(resolveLocalFileSystemURL); + }); + }); + + it('should return a base64 data-uri when not a local file', function() { + // replace cordova file function to call error callback + const failingResolveLocalFileSystemURL = sinon.stub().callsArg(2); + global.window.resolveLocalFileSystemURL = failingResolveLocalFileSystemURL; + + return subject.capture().then(result => { + sinon.assert.called(failingResolveLocalFileSystemURL); + expect(result).to.deep.equal({ + value: 'data:image/jpg;base64,some-uri', + type: 'base64' + }); + }); + }); + }); +}); diff --git a/client/camera/test/buildCameraOptions-spec.ts b/client/camera/test/buildCameraOptions-spec.ts new file mode 100644 index 0000000..7c50a9f --- /dev/null +++ b/client/camera/test/buildCameraOptions-spec.ts @@ -0,0 +1,17 @@ +import { expect } from 'chai'; +import { buildCameraOptions } from '../src/buildCameraOptions'; +import { mockCordovaCamera } from './mocks/camera'; + +describe('buildCameraOptions', function() { + it('should accept a given camera object', function() { + return expect(buildCameraOptions(mockCordovaCamera)).to.be.ok; + }); + it('should return a configuration object', function() { + const opts = buildCameraOptions(mockCordovaCamera); + expect(opts).to.have.property('quality'); + expect(opts).to.have.property('sourceType'); + expect(opts).to.have.property('destinationType'); + expect(opts).to.have.property('encodingType'); + expect(opts).to.have.property('mediaType'); + }); +}); diff --git a/client/camera/test/index.ts b/client/camera/test/index.ts index e69de29..31cdb35 100644 --- a/client/camera/test/index.ts +++ b/client/camera/test/index.ts @@ -0,0 +1 @@ +/// diff --git a/client/camera/test/mocks/camera.ts b/client/camera/test/mocks/camera.ts new file mode 100644 index 0000000..67f5ddf --- /dev/null +++ b/client/camera/test/mocks/camera.ts @@ -0,0 +1,27 @@ +import { stub } from 'sinon'; +export const mockCordovaCamera = { + // properties + DestinationType: { + FILE_URI: 1 + }, + EncodingType: { + JPEG: 1 + }, + PictureSourceType: { + CAMERA: 1 + }, + MediaType: { + PICTURE: 1 + }, + // methods + cleanup: stub().callsArgAsync(0), + getPicture: stub().callsArgWithAsync(0, 'some-uri') +}; + +declare var global: any; +global.window = global.window || {}; +global.navigator = global.navigator || {}; +global.window.navigator = global.navigator; + +global.window.camera = mockCordovaCamera; +global.navigator.camera = mockCordovaCamera; diff --git a/client/camera/test/mocks/file.ts b/client/camera/test/mocks/file.ts new file mode 100644 index 0000000..eb69262 --- /dev/null +++ b/client/camera/test/mocks/file.ts @@ -0,0 +1,7 @@ +import { stub } from 'sinon'; +declare var global: any; + +export const resolveLocalFileSystemURL = stub().callsArgAsync(1); + +global.window = global.window || {}; +global.window.resolveLocalFileSystemURL = resolveLocalFileSystemURL; diff --git a/client/filestore-client/package.json b/client/filestore-client/package.json index 2479eb8..7896917 100644 --- a/client/filestore-client/package.json +++ b/client/filestore-client/package.json @@ -29,28 +29,27 @@ "text" ], "report-dir": "coverage_report", - "check-coverage": true, "lines": 75, "functions": 100, "branches": 80 }, "devDependencies": { - "@types/bluebird": "^3.5.16", - "@types/chai": "^4.0.4", - "@types/chai-as-promised": "^7.1.0", + "@types/bluebird": "^3.5.8", + "@types/chai": "^4.0.3", + "@types/chai-as-promised": "7.1.0", "@types/cordova-plugin-file": "0.0.3", "@types/cordova-plugin-file-transfer": "0.0.3", "@types/lodash": "^4.14.73", "@types/mocha": "^2.2.41", "@types/proxyquire": "^1.3.27", - "@types/sinon": "^2.3.7", - "chai": "^4.1.2", + "@types/sinon": "^2.3.3", + "chai": "^4.1.1", "chai-as-promised": "^7.1.1", - "del-cli": "^1.0.0", + "del-cli": "^1.1.0", "mocha": "^4.0.1", "nyc": "^11.1.0", "proxyquire": "^1.8.0", - "sinon": "^4.1.1", + "sinon": "^4.0.1", "source-map-support": "^0.5.0", "ts-node": "^3.3.0", "typescript": "^2.5.0" diff --git a/cloud/filestore/package.json b/cloud/filestore/package.json index 68f6f23..e75e15a 100644 --- a/cloud/filestore/package.json +++ b/cloud/filestore/package.json @@ -51,13 +51,17 @@ "source-map-support": "^0.5.0", "string-to-stream": "^1.1.0", "ts-node": "^3.3.0", - "typescript": "^2.5.0" + "typescript": "^2.5.0", + "@types/chai": "^4.0.3", + "chai": "^4.1.1", + "@types/chai-as-promised": "7.1.0", + "chai-as-promised": "^7.1.1" }, "dependencies": { "@raincatcher/logger": "0.0.1", "base64-stream": "0.1.3", "bluebird": "^3.5.0", - "express": "4.15.4", + "express": "^4.15.4", "gridfs-stream": "^1.1.1", "lodash": "^4.17.4", "mkdirp": "^0.5.1",