Skip to content

Commit

Permalink
ref(sentry10): Remove util functions related to project environments (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagara authored Jun 7, 2019
1 parent c387279 commit 30f3e37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 134 deletions.
33 changes: 0 additions & 33 deletions src/sentry/static/sentry/app/utils/queryString.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,6 @@ export function formatQueryString(qs) {
return qs.trim().replace(/\s+/g, ' ');
}

// returns environment name from query or null if not specified
// Any character can be valid in an environment name but we need to
// check for matching environments with the quotation marks first
// to match the way tag searches are being done
export function getQueryEnvironment(qs) {
// A match with quotes will lazily match any characters within quotation marks
const matchWithQuotes = qs.match(/(?:^|\s)environment:"(.*?)"/);
// A match without quotes will match any non space character
const matchWithoutQuotes = qs.match(/(?:^|\s)environment:([^\s]*)/);

if (matchWithQuotes) {
return matchWithQuotes[1];
} else if (matchWithoutQuotes) {
return matchWithoutQuotes[1];
} else {
return null;
}
}

export function getQueryStringWithEnvironment(qs, env) {
const qsWithoutEnv = qs.replace(/(?:^|\s)environment:[^\s]*/g, '');
return formatQueryString(
env === null ? qsWithoutEnv : `${qsWithoutEnv} environment:${env}`
);
}

export function getQueryStringWithoutEnvironment(qs) {
return formatQueryString(qs.replace(/(?:^|\s)environment:[^\s]*/g, ''));
}

export function addQueryParamsToExistingUrl(origUrl, queryParams) {
const url = parseurl({url: origUrl});
if (!url) {
Expand All @@ -50,8 +20,5 @@ export function addQueryParamsToExistingUrl(origUrl, queryParams) {

export default {
formatQueryString,
getQueryEnvironment,
getQueryStringWithEnvironment,
getQueryStringWithoutEnvironment,
addQueryParamsToExistingUrl,
};
110 changes: 9 additions & 101 deletions tests/js/spec/utils/queryString.spec.js
Original file line number Diff line number Diff line change
@@ -1,123 +1,31 @@
import utils from 'app/utils/queryString';

describe('getQueryEnvironment()', function() {
it('returns environment name', function() {
const qs = 'is:unresolved is:unassigned environment:production';
expect(utils.getQueryEnvironment(qs)).toBe('production');
});

// empty environment aka. (No environment) has '' as a name
it('returns empty string environment (the empty environment case)', function() {
const qs = 'is:unresolved is:unassigned environment:';
expect(utils.getQueryEnvironment(qs)).toBe('');
});

it('returns null if no environment specified in query', function() {
const qs = 'is:unresolved is:unassigned';
expect(utils.getQueryEnvironment(qs)).toBe(null);
});

it('handles environment with non word characters', function() {
const qs = 'is:unresolved is:unassigned environment:something.com';
expect(utils.getQueryEnvironment(qs)).toBe('something.com');
});

it('handles environment provided with quote marks', function() {
const qs = 'is:unresolved is:unassigned environment:"production"';
expect(utils.getQueryEnvironment(qs)).toBe('production');
});

it('handles environment names with space and quote marks', function() {
const qs = 'is:unresolved is:unassigned environment:"my environment"';
expect(utils.getQueryEnvironment(qs)).toBe('my environment');
});

it('handles query property similar to `environment`', function() {
const qs = 'test_environment:development';
expect(utils.getQueryEnvironment(qs)).toBe(null);
});
});

describe('getQueryStringWithEnvironment', function() {
it('replaces environment in query string', function() {
const qs = 'is:unresolved environment:development is:unassigned';
expect(utils.getQueryStringWithEnvironment(qs, 'staging')).toBe(
'is:unresolved is:unassigned environment:staging'
);
});

it('handles empty string environment', function() {
const qs = 'is:unresolved environment:development is:unassigned';
expect(utils.getQueryStringWithEnvironment(qs, '')).toBe(
'is:unresolved is:unassigned environment:'
);
});

it('handles null environment', function() {
const qs = 'is:unresolved environment:development is:unassigned';
expect(utils.getQueryStringWithEnvironment(qs, null)).toBe(
'is:unresolved is:unassigned'
);
});

it('handles environment with non word characters', function() {
const qs = 'is:unresolved environment:something.com is:unassigned';
expect(utils.getQueryStringWithEnvironment(qs, 'test.com')).toBe(
'is:unresolved is:unassigned environment:test.com'
);
});

it('handles query property similar to `environment`', function() {
const qs = 'test_environment:development';
expect(utils.getQueryStringWithEnvironment(qs, 'test.com')).toBe(
'test_environment:development environment:test.com'
);
});
});

describe('getQueryStringWithoutEnvironment', function() {
it('removes environment from querystring', function() {
const qs = 'is:unresolved environment:development is:unassigned';
expect(utils.getQueryStringWithoutEnvironment(qs)).toBe(
'is:unresolved is:unassigned'
);
});

it('removes empty environment from querystring', function() {
const qs = 'is:unresolved environment: is:unassigned';
expect(utils.getQueryStringWithoutEnvironment(qs)).toBe(
'is:unresolved is:unassigned'
);
});

it('handles query property similar to `environment`', function() {
const qs = 'test_environment:development';
expect(utils.getQueryStringWithoutEnvironment(qs)).toBe(
'test_environment:development'
);
});
});

describe('addQueryParamsToExistingUrl', function() {
it('adds new query params to existing query params', function() {
const url = 'https://example.com?value=3';
const newParams = {id: 4};
const newParams = {
id: 4,
};
expect(utils.addQueryParamsToExistingUrl(url, newParams)).toBe(
'https://example.com/?id=4&value=3'
);
});

it('adds new query params without existing query params', function() {
const url = 'https://example.com';
const newParams = {id: 4};
const newParams = {
id: 4,
};
expect(utils.addQueryParamsToExistingUrl(url, newParams)).toBe(
'https://example.com/?id=4'
);
});

it('returns empty string no url is passed', function() {
let url;
const newParams = {id: 4};
const newParams = {
id: 4,
};
expect(utils.addQueryParamsToExistingUrl(url, newParams)).toBe('');
});
});

0 comments on commit 30f3e37

Please sign in to comment.