@lighthouse/sdk
Advanced tools
Comparing version 7.1.2 to 7.2.0-beta-1
@@ -163,3 +163,7 @@ 'use strict'; | ||
*/ | ||
function save(params, payload, id) { | ||
function save() { | ||
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var payload = arguments[1]; | ||
var id = arguments[2]; | ||
return function (dispatch, getState) { | ||
@@ -174,2 +178,6 @@ var state = getState(); | ||
} | ||
if (params.withProperties) { | ||
var properties = (0, _get2.default)(state, 'app.properties'); | ||
payload.properties = properties; | ||
} | ||
var headers = headersFn(params, state); | ||
@@ -176,0 +184,0 @@ return dispatch(saveRequest(endpoint, headers, params, payload, id)); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.SET_REGION = exports.SET_ENDPOINTS = exports.SET_ZONE = exports.SET_LOCATION = exports.SET_APPLICATION = exports.GET_CONFIG_ERROR = exports.GET_CONFIG_SUCCESS = exports.GET_CONFIG_REQUEST = exports.CONNECTION_SUCCESS = exports.CONNECTION_ERROR = undefined; | ||
exports.SET_PROPERTIES = exports.SET_REGION = exports.SET_ENDPOINTS = exports.SET_ZONE = exports.SET_LOCATION = exports.SET_APPLICATION = exports.GET_CONFIG_ERROR = exports.GET_CONFIG_SUCCESS = exports.GET_CONFIG_REQUEST = exports.CONNECTION_SUCCESS = exports.CONNECTION_ERROR = undefined; | ||
@@ -20,2 +20,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.connectionError = connectionError; | ||
exports.setProperties = setProperties; | ||
exports.getRegionUrl = getRegionUrl; | ||
@@ -78,2 +79,3 @@ exports.applicationParamsFn = applicationParamsFn; | ||
var SET_REGION = exports.SET_REGION = 'lighthouse/app/SET_REGION'; | ||
var SET_PROPERTIES = exports.SET_PROPERTIES = 'lighthouse/app/SET_PROPERTIES'; | ||
@@ -126,2 +128,7 @@ function reducer() { | ||
case SET_PROPERTIES: | ||
return state.update('properties', function (properties) { | ||
return properties.merge(action.properties); | ||
}); | ||
default: | ||
@@ -206,2 +213,9 @@ return state; | ||
function setProperties(properties) { | ||
return { | ||
type: SET_PROPERTIES, | ||
properties: properties | ||
}; | ||
} | ||
/** | ||
@@ -208,0 +222,0 @@ * Returns the current url for set region or empty string when missing required |
@@ -138,3 +138,3 @@ import omit from 'lodash/omit' | ||
*/ | ||
function save(params, payload, id) { | ||
function save(params = {}, payload, id) { | ||
return (dispatch, getState) => { | ||
@@ -149,2 +149,6 @@ const state = getState() | ||
} | ||
if (params.withProperties) { | ||
const properties = get(state, 'app.properties') | ||
payload.properties = properties | ||
} | ||
const headers = headersFn(params, state) | ||
@@ -151,0 +155,0 @@ return dispatch(saveRequest(endpoint, headers, params, payload, id)) |
@@ -519,2 +519,45 @@ import actionTypesBuilder from '../../action-types' | ||
it('should pass app properties with payload if passed as option', function(done) { | ||
const payload = { | ||
name: 'Taj Mahal' | ||
} | ||
const response = Object.assign({}, payload, { | ||
_id: '1', | ||
created: 'Thu Jan 01 2015 00:00:00 GMT+1100 (AEDT)' | ||
}) | ||
mockApi | ||
.post(`${baseUrl}${resource}`) | ||
.reply(201, response) | ||
const expectedActions = [ | ||
{ | ||
type: actions.SAVE_REQUEST, | ||
data: { | ||
...payload, | ||
properties: { | ||
deviceManufaturer: 'Apple', | ||
devicePlatform: 'iOS', | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: actions.SAVE_SUCCESS, | ||
data: response | ||
} | ||
] | ||
const store = mockStore({ | ||
app: { | ||
properties: { | ||
deviceManufaturer: 'Apple', | ||
devicePlatform: 'iOS', | ||
} | ||
} | ||
}, expectedActions, done) | ||
const params = { | ||
withProperties: true, | ||
} | ||
store.dispatch(actionCreators.save(params, payload)) | ||
}) | ||
it('should handle an save request for an existing location', function(done) { | ||
@@ -521,0 +564,0 @@ const payload = { |
@@ -40,2 +40,3 @@ /* | ||
export const SET_REGION = 'lighthouse/app/SET_REGION' | ||
export const SET_PROPERTIES = 'lighthouse/app/SET_PROPERTIES' | ||
@@ -91,2 +92,5 @@ export function reducer(state = Immutable({}), action = {}) { | ||
case SET_PROPERTIES: | ||
return state.update('properties', properties => properties.merge(action.properties)) | ||
default: | ||
@@ -173,2 +177,10 @@ return state | ||
export function setProperties(properties) { | ||
return { | ||
type: SET_PROPERTIES, | ||
properties, | ||
} | ||
} | ||
/** | ||
@@ -175,0 +187,0 @@ * Returns the current url for set region or empty string when missing required |
@@ -233,2 +233,31 @@ import * as module from './' | ||
}) | ||
it('should handle a SET_DEVICE_PROPERTIES', () => { | ||
const initialState = { | ||
// NOTE ensure properties are merged with existing | ||
properties: { | ||
systemVersion: '9.1', | ||
}, | ||
} | ||
const action = { | ||
type: module.SET_PROPERTIES, | ||
properties: { | ||
appName: 'Lighthouse.io', | ||
appVersion: '5.0.1', | ||
deviceUUID: 'ba39b74022172a77', | ||
deviceManufaturer: 'Apple', | ||
devicePlatform: 'iOS', | ||
deviceModel: 'iPhone 7', | ||
systemName: 'iPhone OS', | ||
userAgent: 'Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D)', | ||
timezone: 'Australia/Melbourne', | ||
}, | ||
} | ||
reducer(initialState, action).should.have.properties({ | ||
properties: { | ||
...action.properties, | ||
systemVersion: '9.1', | ||
}, | ||
}) | ||
}) | ||
}) | ||
@@ -310,2 +339,14 @@ | ||
}) | ||
it('should return action for setProperties', () => { | ||
module.setProperties({ | ||
deviceManufaturer: 'Apple', | ||
devicePlatform: 'iOS', | ||
}).should.eql({ | ||
type: module.SET_PROPERTIES, | ||
properties: { | ||
deviceManufaturer: 'Apple', | ||
devicePlatform: 'iOS', | ||
} | ||
}) | ||
}) | ||
}) | ||
@@ -312,0 +353,0 @@ |
{ | ||
"name": "@lighthouse/sdk", | ||
"version": "7.1.2", | ||
"version": "7.2.0-beta-1", | ||
"description": "Lighthouse.io SDK for JavaScript applications", | ||
@@ -8,6 +8,7 @@ "main": "build/index.js", | ||
"clean": "rm -r -f build/*", | ||
"release": "npm run clean && node_modules/.bin/babel lib --ignore *.test.js --out-dir build", | ||
"lint": "eslint lib", | ||
"release": "yarn run clean && node_modules/.bin/babel lib --ignore *.test.js --out-dir build", | ||
"lint": "node_modules/.bin/eslint lib", | ||
"test": "NODE_ENV=test node_modules/.bin/mocha --compilers js:babel-core/register --reporter dot --require should --require jsdom-global/register --grep ${grep:-''} 'lib/**/*.test.js'", | ||
"test:watch": "npm test -- --watch" | ||
"test:ci": "yarn run test -- --reporter mocha-junit-reporter", | ||
"test:watch": "yarn test -- --watch" | ||
}, | ||
@@ -32,7 +33,11 @@ "repository": { | ||
"babel-preset-es2015": "^6.3.13", | ||
"eslint": "^2.11.1", | ||
"eslint-config-airbnb": "^9.0.1", | ||
"eslint": "^3.13.0", | ||
"eslint-config-airbnb": "^14.0.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^3.0.2", | ||
"eslint-plugin-react": "^6.9.0", | ||
"jsdom": "9.8.3", | ||
"jsdom-global": "2.1.0", | ||
"mocha": "^2.3.4", | ||
"mocha-junit-reporter": "^1.13.0", | ||
"nock": "^2.15.0", | ||
@@ -39,0 +44,0 @@ "should": "^9.0.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
693796
247
16624
20
2