atlassian-connect-js-request
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -183,3 +183,8 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.connectHostRequest = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
ajaxOptions = handleMultipartRequest(ajaxOptions); | ||
} | ||
// if it's not form data, append it to the URL, matching jquery's encoding | ||
} else if (ajaxOptions.data && typeof ajaxOptions.data === 'object') { | ||
Object.keys(ajaxOptions.data).forEach(function (key) { | ||
ajaxOptions.url += (ajaxOptions.url.indexOf('?') >= 0 ? '&' : '?') + encodeURIComponent(key) + '=' + encodeURIComponent(ajaxOptions.data[key]); | ||
}); | ||
} | ||
@@ -186,0 +191,0 @@ // set the experimental header |
{ | ||
"name": "atlassian-connect-js-request", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Request module for Atlassian Connect", | ||
@@ -23,2 +23,2 @@ "devDependencies": { | ||
} | ||
} | ||
} |
@@ -88,2 +88,24 @@ import requestHost, { stripJWTUrls } from '../../src/host'; | ||
it('appends data to url as query params. as per jquery', () => { | ||
const requestOptions = { | ||
url: '/some/url', | ||
data: { | ||
a: 'a data', | ||
b: 'more data' | ||
} | ||
} | ||
const callback = jasmine.createSpy('callback'); | ||
callback._context = defaultContext; | ||
jasmine.Ajax.stubRequest(/.*/).andReturn({ | ||
'responseText': 'immediate response' | ||
}); | ||
requestHost.request(requestOptions, callback); | ||
expect(jasmine.Ajax.requests.mostRecent().method).toBe('GET'); | ||
expect(jasmine.Ajax.requests.mostRecent().params).toEqual(requestOptions.data); | ||
expect(jasmine.Ajax.requests.mostRecent().requestHeaders['Accept']).toEqual('*/*'); | ||
expect(jasmine.Ajax.requests.mostRecent().requestHeaders['AP-Client-Key']).toEqual(defaultContext.extension.addon_key); | ||
expect(jasmine.Ajax.requests.mostRecent().url).toContain('/some/url?a=a%20data&b=more%20data&_r='); | ||
}); | ||
it('headers are properly whitelisted', () => { | ||
@@ -90,0 +112,0 @@ const ifMatchVal = 'if-match-value'; |
@@ -180,2 +180,7 @@ /** | ||
ajaxOptions = handleMultipartRequest(ajaxOptions); | ||
// if it's not form data, append it to the URL, matching jquery's encoding | ||
} else if (ajaxOptions.data && typeof ajaxOptions.data === 'object') { | ||
Object.keys(ajaxOptions.data).forEach(function (key) { | ||
ajaxOptions.url += (ajaxOptions.url.indexOf('?') >= 0 ? '&' : '?') + encodeURIComponent(key) + '=' + encodeURIComponent(ajaxOptions.data[key]); | ||
}); | ||
} | ||
@@ -182,0 +187,0 @@ |
54543
1210