Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge 6669259 into f25b881
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobueno committed Nov 10, 2017
2 parents f25b881 + 6669259 commit ae8c32e
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 15 deletions.
11 changes: 8 additions & 3 deletions client/camera/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,7 +29,6 @@
"text"
],
"report-dir": "coverage_report",
"check-coverage": true,
"lines": 75,
"functions": 100,
"branches": 80
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions client/camera/src/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface CaptureResponse {
type optionsBuilderFn = (camera: any) => CameraOptions;

export class Camera {
protected initPromise: Promise<CameraOptions>;
protected options: CameraOptions;
public options: CameraOptions;
public initPromise: Promise<CameraOptions>;

constructor(optionsBuilderFunction?: optionsBuilderFn) {
this.init(optionsBuilderFunction);
Expand Down
57 changes: 57 additions & 0 deletions client/camera/test/Camera-spec.ts
Original file line number Diff line number Diff line change
@@ -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'
});
});
});
});
});
17 changes: 17 additions & 0 deletions client/camera/test/buildCameraOptions-spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
1 change: 1 addition & 0 deletions client/camera/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="mocha" />
27 changes: 27 additions & 0 deletions client/camera/test/mocks/camera.ts
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions client/camera/test/mocks/file.ts
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 7 additions & 8 deletions client/filestore-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions cloud/filestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ae8c32e

Please sign in to comment.