fix: Sync parameters validation for the old and the new set alert text endpoints
MODIFY
lib/protocol/routes.js
lib/protocol/routes.js
@@ -3,6 +3,14 @@ import { util } from 'appium-support';
import { DEFAULT_BASE_PATH, PROTOCOLS } from './protocol';
+const SET_ALERT_TEXT_PAYLOAD_PARAMS = {
+ validate: (jsonObj) => (!util.hasValue(jsonObj.value) && !util.hasValue(jsonObj.text)) &&
+ 'either "text" or "value" must be set',
+ optional: ['value', 'text'],
+ // Prefer 'value' since it's more backward-compatible.
+ makeArgs: (jsonObj) => [jsonObj.value || jsonObj.text],
+};
+
// define the routes, mapping of HTTP methods to particular driver commands,
// and any parameters that are expected in a request
// parameters can be `required` or `optional`
@@ -603,7 +611,10 @@ const METHOD_MAP = {
// old alerts
'/session/:sessionId/alert_text': {
GET: {command: 'getAlertText'},
- POST: {command: 'setAlertText', payloadParams: {required: ['text']}}
+ POST: {
+ command: 'setAlertText',
+ payloadParams: SET_ALERT_TEXT_PAYLOAD_PARAMS,
+ }
},
'/session/:sessionId/accept_alert': {
POST: {command: 'postAcceptAlert'}
@@ -616,13 +627,7 @@ const METHOD_MAP = {
GET: {command: 'getAlertText'},
POST: {
command: 'setAlertText',
- payloadParams: {
- validate: (jsonObj) => (!util.hasValue(jsonObj.value) && !util.hasValue(jsonObj.text)) &&
- 'either "text" or "value" must be set',
- optional: ['value', 'text'],
- // Prefer 'value' since it's more backward-compatible.
- makeArgs: (jsonObj) => [jsonObj.value || jsonObj.text],
- }
+ payloadParams: SET_ALERT_TEXT_PAYLOAD_PARAMS,
}
},
'/session/:sessionId/alert/accept': {

MODIFY
test/protocol/routes-specs.js
test/protocol/routes-specs.js
@@ -40,7 +40,7 @@ describe('Protocol', function () {
}
let hash = shasum.digest('hex').substring(0, 8);
// Modify the hash whenever the protocol has intentionally been modified.
- hash.should.equal('1a27532d');
+ hash.should.equal('86dc6c5b');
});
});

fix: Sync parameters validation for the old and the new set alert text endpoints (#369)