Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { expect } from 'chai';
import { defaultPreferencesInstance } from 'compass-preferences-model';
import sinon from 'sinon';

import reducer, {
toggleInputDocumentsCollapsed,
updateInputDocuments,
loadingInputDocuments,
refreshInputDocuments,
ActionTypes,
} from './input-documents';
import { expect } from 'chai';
import type { RootState } from '.';
import type { DataService } from './data-service';

describe('input documents module', function () {
afterEach(function () {
sinon.restore();
});

describe('#toggleInputDocumentsCollapsed', function () {
it('returns the ActionTypes.CollapseToggled action', function () {
expect(toggleInputDocumentsCollapsed()).to.deep.equal({
Expand All @@ -33,6 +43,53 @@ describe('input documents module', function () {
});
});

describe('#refreshInputDocuments', function () {
it('should apply maxTimeMS to the aggregation when it is set', async function () {
const refreshInputDocumentsThunk = refreshInputDocuments();

const mockAggregate = sinon.stub().resolves([]);
const mockState: Partial<RootState> = {
dataService: {
dataService: {
aggregate: mockAggregate,
} as unknown as DataService,
},
namespace: 'test.namespace',
maxTimeMS: undefined,
settings: {
isExpanded: false,
isCommentMode: false,
isDirty: false,
limit: 10,
sampleSize: 10,
},
};

await refreshInputDocumentsThunk(
sinon.stub(),
() => mockState as RootState,
{ preferences: defaultPreferencesInstance } as any
);

expect(mockAggregate.calledOnce).to.be.true;
expect(mockAggregate.firstCall.args[2]).to.deep.equal({
maxTimeMS: 60_000,
});

mockState.maxTimeMS = 1000;
await refreshInputDocumentsThunk(
sinon.stub(),
() => mockState as RootState,
{ preferences: defaultPreferencesInstance } as any
);

expect(mockAggregate.calledTwice).to.be.true;
expect(mockAggregate.secondCall.args[2]).to.deep.equal({
maxTimeMS: 1000,
});
});
});

describe('#reducer', function () {
context(
'when the action is not toggle input documents collapsed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provide
import type { PipelineBuilderThunkAction } from '.';
import type { AnyAction } from 'redux';
import { isAction } from '../utils/is-action';
import { DEFAULT_MAX_TIME_MS } from '../constants';

export enum ActionTypes {
CollapseToggled = 'aggregations/input-documents/CollapseToggled',
Expand Down Expand Up @@ -111,9 +112,10 @@ export const refreshInputDocuments = (): PipelineBuilderThunkAction<
}

const options = {
maxTimeMS: capMaxTimeMSAtPreferenceLimit(preferences, maxTimeMS) as
| number
| undefined,
maxTimeMS: capMaxTimeMSAtPreferenceLimit(
preferences,
maxTimeMS ?? DEFAULT_MAX_TIME_MS
),
};

const aggregateOptions = { ...options };
Expand Down