Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sc 84853/fix broken tests in dependencies 2 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.eslintrc.js
node_modules
.idea
.DS_Store
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org)

## [1.0.6] - 2025-01-17
### Fixed
- replace duplicated tests copied from custom module with wrapper-specific tests
- update dependencies ([sc-84853](https://app.shortcut.com/active-prospect/story/84853/fix-broken-tests-in-dependencies))

## [1.0.5] - 2021-02-25
### Fixed
- fix npm vulnerabilities
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "LeadConduit form POST integration",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "mocha",
"fixlint": "eslint . --fix",
"lint": "eslint ."
},
"repository": {
"type": "git",
Expand All @@ -19,7 +21,6 @@
"leadconduit-custom": "^2.16.0"
},
"devDependencies": {
"chai": "^4.1.2",
"mocha": "^8.3.0"
"@activeprospect/integration-dev-dependencies": "^2.0.1"
}
}
238 changes: 19 additions & 219 deletions test/form-spec.js
Original file line number Diff line number Diff line change
@@ -1,226 +1,26 @@
// Generated by CoffeeScript 1.10.0
(function() {
var assert, integration, types;
const assert = require('chai').assert;
const integration = require('../lib/form-post');

assert = require('chai').assert;
describe('Wrap of custom integration', function() {

integration = require('../lib/form-post');
it('wraps request', () => {
assert.isFunction(integration.request);
assert.isArray(integration.request.variables());

types = require('leadconduit-types');

describe('Outbound Form POST request', function() {
it('should have url, method, headers, and body', function() {
var vars;
vars = {
url: 'http://foo.bar',
form_field: {
fname: 'Mel',
lname: 'Gibson'
},
header: {
Whatever: 'foo',
Bar: 'baz'
}
};
assert.equal(integration.request(vars).url, 'http://foo.bar');
assert.equal(integration.request(vars).method, 'POST');
assert.equal(integration.request(vars).body, 'fname=Mel&lname=Gibson');
return assert.deepEqual(integration.request(vars).headers, {
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Content-Length': 22,
'Accept': 'application/json;q=0.9,text/xml;q=0.8,application/xml;q=0.7,text/html;q=0.6,text/plain;q=0.5',
'Whatever': 'foo',
'Bar': 'baz'
});
});
it('should send data as ASCII when told to', function() {
var vars;
vars = {
send_ascii: types.boolean.parse('true'),
form_field: {
fname: 'Mêl',
lname: 'Gibson'
}
};
return assert.equal(integration.request(vars).body, 'fname=Mel&lname=Gibson');
});
it('should send data as original UTF-8 when told to', function() {
var vars;
vars = {
send_ascii: types.boolean.parse('false'),
form_field: {
fname: 'Mêl',
lname: 'Gibson'
}
};
return assert.equal(integration.request(vars).body, 'fname=M%C3%AAl&lname=Gibson');
});
it('should allow Content-Type override', function() {
var vars;
vars = {
url: 'http://foo.bar',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
return assert.deepEqual(integration.request(vars).headers, {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': 0,
'Accept': 'application/json;q=0.9,text/xml;q=0.8,application/xml;q=0.7,text/html;q=0.6,text/plain;q=0.5'
});
});
it('should support simple dot-notation', function() {
var vars;
vars = {
form_field: {
'foo.bar.baz': 'bip'
}
};
return assert.equal(integration.request(vars).body, 'foo.bar.baz=bip');
});
it('should support simple bracket notation', function() {
var vars;
vars = {
form_field: {
'profile[what_is_your_interest]': 'whatever'
}
};
return assert.equal(integration.request(vars).body, 'profile%5Bwhat_is_your_interest%5D=whatever');
});
it('should support dot-notation arrays', function() {
var vars;
vars = {
form_field: {
'foo.bar.baz.0': 'bip',
'foo.bar.baz.1': 'bap'
}
};
return assert.equal(integration.request(vars).body, 'foo.bar.baz=bip&foo.bar.baz=bap');
});
it('should compact dot-notation arrays', function() {
var vars;
vars = {
form_field: {
'foo.0': 'bip',
'foo.4': 'bap',
'bar.baz.2': 42,
'bar.baz.9': 55
}
};
return assert.equal(integration.request(vars).body, 'foo=bip&foo=bap&bar.baz=42&bar.baz=55');
});
it('should support dot-notation array reference', function() {
var vars;
vars = {
form_field: {
'foo.bar.baz': ['bip', 'bap']
}
};
return assert.equal(integration.request(vars).body, 'foo.bar.baz=bip&foo.bar.baz=bap');
});
it('should normalize rich types', function() {
var vars;
vars = {
form_field: {
postal_code: types.postal_code.parse('78704'),
phone: types.phone.parse('512-789-1111 x123'),
boolean: types.boolean.parse('T'),
gender: types.gender.parse('F'),
number: types.number.parse('$100,000.00'),
range: types.range.parse('1,000-2,000')
}
};
return assert.equal(integration.request(vars).body, 'postal_code=78704&phone=5127891111x123&boolean=true&gender=female&number=100000&range=1000-2000');
});
it('should normalize rich type array', function() {
var vars;
vars = {
form_field: {
phones: [types.phone.parse('512-789-1111 x123'), types.phone.parse('512-789-2222 x456')]
}
};
return assert.equal(integration.request(vars).body, 'phones=5127891111x123&phones=5127892222x456');
});
it('should use raw value for invalid rich types', function() {
var vars;
vars = {
form_field: {
number: types.number.parse('foo')
}
};
return assert.equal(integration.request(vars).body, 'number=foo');
});
it('should encode form_field names and values by default', function() {
var vars;
vars = {
form_field: {
'foo[bar]': 42,
'foo[baz]': 'zippity[do]'
}
};
return assert.equal(integration.request(vars).body, 'foo%5Bbar%5D=42&foo%5Bbaz%5D=zippity%5Bdo%5D');
});
return it('should not encode form_field names when told not to', function() {
var vars;
vars = {
encode_form_field_names: false,
form_field: {
'foo[bar]': 42,
'foo[baz]': 'zippity[do]'
}
};
return assert.equal(integration.request(vars).body, 'foo[bar]=42&foo[baz]=zippity%5Bdo%5D');
});
const req = integration.request({ url: 'https://example.com' });
assert.equal(req.url, 'https://example.com');
assert.exists(req.method);
assert.isObject(req.headers);
});

describe('Outbound Form POST validation', function() {
const url = 'http://foo.com';
it('should require valid URL', function() {
return assert.equal(integration.validate({}), 'URL is required');
});
it('should require valid search outcome', function() {
return assert.equal(integration.validate({
url,
outcome_on_match: 'donkey'
}), "Outcome on match must be 'success', 'failure', or 'error'");
});
it('should pass validation', function() {
return assert.isUndefined(integration.validate({
url
}));
});
it('should allow valid content-type header', function() {
return assert.isUndefined(integration.validate({
url,
header: {
'Content-Type': 'x-www-form-urlencoded'
}
}));
});
it('should not allow invalid content-type header', function() {
return assert.equal(integration.validate({
url,
header: {
'Content-Type': 'application/json'
}
}), 'Invalid Content-Type header value');
});
it('should not allow content-length header', function() {
return assert.equal(integration.validate({
url,
header: {
'Content-Length': '10'
}
}), 'Content-Length header is not allowed');
});
return it('should not allow accept header', function() {
return assert.equal(integration.validate({
url,
header: {
'Accept': 'text/whatever'
}
}), 'Accept header is not allowed');
});
it('wraps validate', () => {
assert.isFunction(integration.validate);
assert.isNotEmpty(integration.validate({}));
});

}).call(this);
it('wraps response', () => {
assert.isFunction(integration.response);
assert.isArray(integration.response.variables());
assert.exists(integration.response({}, {}, { headers: [] }).outcome);
});
});
Loading