Skip to content

Commit

Permalink
Add tests for URL passthrough params
Browse files Browse the repository at this point in the history
  • Loading branch information
latonv committed Jan 26, 2023
1 parent 5388ebb commit 2054a6a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/search-backend/fulltext-search-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ describe('FulltextSearchBackend', () => {
expect(urlConfig?.credentials).to.equal('include');
});

it('includes scope param from URL if not provided', async () => {
window.location.search = `?scope=boop`;

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('scope')).to.equal('boop');
});

it('includes caching param if provided', async () => {
const cachingParam = JSON.stringify({ bypass: true });
const backend = new FulltextSearchBackend({
Expand All @@ -86,6 +96,17 @@ describe('FulltextSearchBackend', () => {
expect(queryParams.get('caching')).to.equal(cachingParam);
});

it('includes caching param from URL if not provided', async () => {
const cachingParam = JSON.stringify({ bypass: true });
window.location.search = `?caching=${cachingParam}`;

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal(cachingParam);
});

it('can enable debugging by default on all searches', async () => {
const backend = new FulltextSearchBackend({
baseUrl: 'foo.bar',
Expand Down Expand Up @@ -239,4 +260,20 @@ describe('FulltextSearchBackend', () => {
window.fetch = fetchBackup;
console.log = logBackup;
});

it('includes verbose param from URL if not provided', async () => {
window.location.search = `?verbose=1`;

const logBackup = console.log;
const logSpy = Sinon.spy();
console.log = logSpy;

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

expect(logSpy.callCount).to.be.greaterThan(0);
expect(logSpy.args[0][0]).to.equal('\n\n***** RESPONSE RECEIVED *****');

console.log = logBackup;
});
});
37 changes: 37 additions & 0 deletions test/search-backend/metadata-search-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ describe('MetadataSearchBackend', () => {
expect(urlConfig?.credentials).to.equal('include');
});

it('includes scope param from URL if not provided', async () => {
window.location.search = `?scope=boop`;

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('scope')).to.equal('boop');
});

it('includes caching param if provided', async () => {
const cachingParam = JSON.stringify({ bypass: true });
const backend = new MetadataSearchBackend({
Expand All @@ -86,6 +96,17 @@ describe('MetadataSearchBackend', () => {
expect(queryParams.get('caching')).to.equal(cachingParam);
});

it('includes caching param from URL if not provided', async () => {
const cachingParam = JSON.stringify({ bypass: true });
window.location.search = `?caching=${cachingParam}`;

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal(cachingParam);
});

it('can enable debugging by default on all searches', async () => {
const backend = new MetadataSearchBackend({
baseUrl: 'foo.bar',
Expand Down Expand Up @@ -239,4 +260,20 @@ describe('MetadataSearchBackend', () => {
window.fetch = fetchBackup;
console.log = logBackup;
});

it('includes verbose param from URL if not provided', async () => {
window.location.search = `?verbose=1`;

const logBackup = console.log;
const logSpy = Sinon.spy();
console.log = logSpy;

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

expect(logSpy.callCount).to.be.greaterThan(0);
expect(logSpy.args[0][0]).to.equal('\n\n***** RESPONSE RECEIVED *****');

console.log = logBackup;
});
});

0 comments on commit 2054a6a

Please sign in to comment.