From 30f3e373bc7c761c01b24c942cd2eac112208990 Mon Sep 17 00:00:00 2001 From: Lyn Nagara Date: Fri, 7 Jun 2019 10:07:39 -0700 Subject: [PATCH] ref(sentry10): Remove util functions related to project environments (#13580) --- .../static/sentry/app/utils/queryString.jsx | 33 ------ tests/js/spec/utils/queryString.spec.js | 110 ++---------------- 2 files changed, 9 insertions(+), 134 deletions(-) diff --git a/src/sentry/static/sentry/app/utils/queryString.jsx b/src/sentry/static/sentry/app/utils/queryString.jsx index 2a66be52e0a6e1..e9bbcd56cb0af9 100644 --- a/src/sentry/static/sentry/app/utils/queryString.jsx +++ b/src/sentry/static/sentry/app/utils/queryString.jsx @@ -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) { @@ -50,8 +20,5 @@ export function addQueryParamsToExistingUrl(origUrl, queryParams) { export default { formatQueryString, - getQueryEnvironment, - getQueryStringWithEnvironment, - getQueryStringWithoutEnvironment, addQueryParamsToExistingUrl, }; diff --git a/tests/js/spec/utils/queryString.spec.js b/tests/js/spec/utils/queryString.spec.js index 3d9a7aa6ca83a0..aca4b3d22cc053 100644 --- a/tests/js/spec/utils/queryString.spec.js +++ b/tests/js/spec/utils/queryString.spec.js @@ -1,107 +1,11 @@ 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' ); @@ -109,7 +13,9 @@ describe('addQueryParamsToExistingUrl', function() { 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' ); @@ -117,7 +23,9 @@ describe('addQueryParamsToExistingUrl', function() { 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(''); }); });