123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- import {ReleaseFixture} from 'sentry-fixture/release';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {getReleaseBounds, getReleaseParams, searchReleaseVersion} from './index';
- describe('releases/utils', () => {
- describe('getReleaseBounds', () => {
- it('returns start and end of a release', () => {
- expect(getReleaseBounds(ReleaseFixture())).toEqual({
- releaseStart: '2020-03-23T01:02:00Z',
- releaseEnd: '2020-03-24T02:04:59Z',
- type: 'normal',
- });
- });
- it('higher last session takes precendence over last event', () => {
- expect(
- getReleaseBounds(
- ReleaseFixture({
- currentProjectMeta: {
- sessionsUpperBound: '2020-03-24T03:04:55Z',
- firstReleaseVersion: null,
- lastReleaseVersion: null,
- nextReleaseVersion: null,
- prevReleaseVersion: null,
- sessionsLowerBound: null,
- },
- })
- )
- ).toEqual({
- releaseStart: '2020-03-23T01:02:00Z',
- releaseEnd: '2020-03-24T03:04:59Z',
- type: 'normal',
- });
- });
- it('there is no last session/event, it fallbacks to now', () => {
- expect(getReleaseBounds(ReleaseFixture({lastEvent: undefined}))).toEqual({
- releaseStart: '2020-03-23T01:02:00Z',
- releaseEnd: '2017-10-17T02:41:59Z',
- type: 'normal',
- });
- });
- it('adds 1 minute to end if start and end are within same minute', () => {
- expect(
- getReleaseBounds(
- ReleaseFixture({
- dateCreated: '2020-03-23T01:02:30Z',
- lastEvent: '2020-03-23T01:02:39Z',
- })
- )
- ).toEqual({
- releaseStart: '2020-03-23T01:02:00Z',
- releaseEnd: '2020-03-23T01:03:59Z',
- type: 'normal',
- });
- });
- it('clamps active releases lasting longer than 90 days', () => {
- expect(
- getReleaseBounds(
- ReleaseFixture({
- dateCreated: '2017-05-17T02:41:20Z',
- lastEvent: '2017-10-12T02:41:20Z',
- })
- )
- ).toEqual({
- releaseStart: '2017-07-19T02:41:20Z',
- releaseEnd: '2017-10-12T02:41:59Z',
- type: 'clamped',
- });
- });
- it('defaults ancient releases to last 90 days', () => {
- expect(
- getReleaseBounds(
- ReleaseFixture({
- dateCreated: '2010-05-17T02:41:20Z',
- lastEvent: '2011-10-17T02:41:20Z',
- })
- )
- ).toEqual({
- releaseStart: '2017-07-19T02:41:20Z',
- releaseEnd: '2017-10-17T02:41:20Z',
- type: 'ancient',
- });
- });
- it('handles no lastEvent for ancient releases', () => {
- expect(
- getReleaseBounds(
- ReleaseFixture({
- dateCreated: '2010-05-17T02:41:20Z',
- lastEvent: undefined,
- })
- )
- ).toEqual({
- releaseStart: '2017-07-19T02:41:20Z',
- releaseEnd: '2017-10-17T02:41:20Z',
- type: 'ancient',
- });
- });
- });
- describe('getReleaseParams', () => {
- const {router} = initializeOrg();
- const releaseBounds = getReleaseBounds(ReleaseFixture());
- it('returns params related to a release', () => {
- const location = {
- ...router.location,
- query: {
- pageStatsPeriod: '30d',
- project: ['456'],
- environment: ['prod'],
- somethingBad: 'meh',
- },
- };
- expect(
- getReleaseParams({
- location,
- releaseBounds,
- })
- ).toEqual({
- statsPeriod: '30d',
- project: ['456'],
- environment: ['prod'],
- });
- });
- it('returns release start/end if no other datetime is present', () => {
- expect(
- getReleaseParams({
- location: {...router.location, query: {}},
- releaseBounds,
- })
- ).toEqual({
- start: '2020-03-23T01:02:00Z',
- end: '2020-03-24T02:04:59Z',
- });
- });
- it('returns correct start/end when zoomed in', () => {
- expect(
- getReleaseParams({
- location: {
- ...router.location,
- query: {pageStart: '2021-03-23T01:02:30Z', pageEnd: '2022-03-23T01:02:30Z'},
- },
- releaseBounds,
- })
- ).toEqual({
- start: '2021-03-23T01:02:30.000',
- end: '2022-03-23T01:02:30.000',
- });
- });
- });
- });
- describe('searchReleaseVersion()', function () {
- it('should escape quotes', function () {
- expect(searchReleaseVersion('com.sentry.go_app@"1.0.0-chore"')).toBe(
- 'release:"com.sentry.go_app@\\"1.0.0-chore\\""'
- );
- });
- });
|