Skip to content

ref(sentry10): Remove util functions related to project environments #13580

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

Merged
merged 2 commits into from
Jun 7, 2019
Merged
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
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('');
});
});