mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Don't restore name/folder on history change (Fixes #786)
This commit is contained in:
parent
676ac58b8b
commit
88286bbf94
@ -180,8 +180,8 @@ describe('migrate()', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'foo', value: 'bar', disabled: false},
|
||||
{name: 'baz', value: '{{ hello }}', disabled: false}
|
||||
{name: 'foo', value: 'bar'},
|
||||
{name: 'baz', value: '{{ hello }}'}
|
||||
]
|
||||
},
|
||||
url: ''
|
||||
@ -201,8 +201,8 @@ describe('migrate()', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'foo', value: 'bar', disabled: false},
|
||||
{name: 'baz', value: '{{ hello }}', disabled: false}
|
||||
{name: 'foo', value: 'bar'},
|
||||
{name: 'baz', value: '{{ hello }}'}
|
||||
]
|
||||
},
|
||||
url: ''
|
||||
@ -222,7 +222,7 @@ describe('migrate()', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: '{"foo": "bar"}', value: '', disabled: false}
|
||||
{name: '{"foo": "bar"}', value: ''}
|
||||
]
|
||||
},
|
||||
url: ''
|
||||
|
@ -7,13 +7,14 @@ export const type = 'RequestVersion';
|
||||
export const prefix = 'rvr';
|
||||
export const canDuplicate = false;
|
||||
|
||||
const FIELDS_TO_IGNORE_IN_REQUEST_DIFF = [
|
||||
const FIELDS_TO_IGNORE = [
|
||||
'_id',
|
||||
'type',
|
||||
'created',
|
||||
'modified',
|
||||
'metaSortKey',
|
||||
'description',
|
||||
'parentId',
|
||||
'name'
|
||||
];
|
||||
|
||||
@ -65,8 +66,15 @@ export async function restore (requestVersionId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const request = decompressObject(requestVersion.compressedRequest);
|
||||
return models.request.update(request);
|
||||
const requestPatch = decompressObject(requestVersion.compressedRequest);
|
||||
const originalRequest = await models.request.getById(requestPatch._id);
|
||||
|
||||
// Only restore fields that aren't blacklisted
|
||||
for (const field of FIELDS_TO_IGNORE) {
|
||||
delete requestPatch[field];
|
||||
}
|
||||
|
||||
return models.request.update(originalRequest, requestPatch);
|
||||
}
|
||||
|
||||
function _diffRequests (rOld, rNew) {
|
||||
@ -76,7 +84,7 @@ function _diffRequests (rOld, rNew) {
|
||||
|
||||
for (const key of Object.keys(rOld)) {
|
||||
// Skip fields that aren't useful
|
||||
if (FIELDS_TO_IGNORE_IN_REQUEST_DIFF.includes(key)) {
|
||||
if (FIELDS_TO_IGNORE.includes(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -52,10 +52,10 @@ describe('authorization_code', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'grant_type', value: 'authorization_code', disabled: false},
|
||||
{name: 'code', value: 'code_123', disabled: false},
|
||||
{name: 'redirect_uri', value: REDIRECT_URI, disabled: false},
|
||||
{name: 'state', value: STATE, disabled: false}
|
||||
{name: 'grant_type', value: 'authorization_code'},
|
||||
{name: 'code', value: 'code_123'},
|
||||
{name: 'redirect_uri', value: REDIRECT_URI},
|
||||
{name: 'state', value: STATE}
|
||||
]
|
||||
},
|
||||
headers: [
|
||||
@ -113,12 +113,12 @@ describe('authorization_code', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'grant_type', value: 'authorization_code', disabled: false},
|
||||
{name: 'code', value: 'code_123', disabled: false},
|
||||
{name: 'redirect_uri', value: REDIRECT_URI, disabled: false},
|
||||
{name: 'state', value: STATE, disabled: false},
|
||||
{name: 'client_id', value: CLIENT_ID, disabled: false},
|
||||
{name: 'client_secret', value: CLIENT_SECRET, disabled: false}
|
||||
{name: 'grant_type', value: 'authorization_code'},
|
||||
{name: 'code', value: 'code_123'},
|
||||
{name: 'redirect_uri', value: REDIRECT_URI},
|
||||
{name: 'state', value: STATE},
|
||||
{name: 'client_id', value: CLIENT_ID},
|
||||
{name: 'client_secret', value: CLIENT_SECRET}
|
||||
]
|
||||
},
|
||||
headers: [
|
||||
|
@ -44,8 +44,8 @@ describe('client_credentials', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'grant_type', value: 'client_credentials', disabled: false},
|
||||
{name: 'scope', value: SCOPE, disabled: false}
|
||||
{name: 'grant_type', value: 'client_credentials'},
|
||||
{name: 'scope', value: SCOPE}
|
||||
]
|
||||
},
|
||||
headers: [
|
||||
@ -98,10 +98,10 @@ describe('client_credentials', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'grant_type', value: 'client_credentials', disabled: false},
|
||||
{name: 'scope', value: SCOPE, disabled: false},
|
||||
{name: 'client_id', value: CLIENT_ID, disabled: false},
|
||||
{name: 'client_secret', value: CLIENT_SECRET, disabled: false}
|
||||
{name: 'grant_type', value: 'client_credentials'},
|
||||
{name: 'scope', value: SCOPE},
|
||||
{name: 'client_id', value: CLIENT_ID},
|
||||
{name: 'client_secret', value: CLIENT_SECRET}
|
||||
]
|
||||
},
|
||||
headers: [
|
||||
|
@ -48,10 +48,10 @@ describe('password', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'grant_type', value: 'password', disabled: false},
|
||||
{name: 'username', value: USERNAME, disabled: false},
|
||||
{name: 'password', value: PASSWORD, disabled: false},
|
||||
{name: 'scope', value: SCOPE, disabled: false}
|
||||
{name: 'grant_type', value: 'password'},
|
||||
{name: 'username', value: USERNAME},
|
||||
{name: 'password', value: PASSWORD},
|
||||
{name: 'scope', value: SCOPE}
|
||||
]
|
||||
},
|
||||
headers: [
|
||||
@ -107,12 +107,12 @@ describe('password', () => {
|
||||
body: {
|
||||
mimeType: 'application/x-www-form-urlencoded',
|
||||
params: [
|
||||
{name: 'grant_type', value: 'password', disabled: false},
|
||||
{name: 'username', value: USERNAME, disabled: false},
|
||||
{name: 'password', value: PASSWORD, disabled: false},
|
||||
{name: 'scope', value: SCOPE, disabled: false},
|
||||
{name: 'client_id', value: CLIENT_ID, disabled: false},
|
||||
{name: 'client_secret', value: CLIENT_SECRET, disabled: false}
|
||||
{name: 'grant_type', value: 'password'},
|
||||
{name: 'username', value: USERNAME},
|
||||
{name: 'password', value: PASSWORD},
|
||||
{name: 'scope', value: SCOPE},
|
||||
{name: 'client_id', value: CLIENT_ID},
|
||||
{name: 'client_secret', value: CLIENT_SECRET}
|
||||
]
|
||||
},
|
||||
headers: [
|
||||
|
Loading…
Reference in New Issue
Block a user