Skip to content

Commit

Permalink
fix(fetch): cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Oct 24, 2024
1 parent e248db8 commit 3d20b2e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 41 deletions.
8 changes: 4 additions & 4 deletions packages/operators/src/fetch/autoPagination.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { concatAll, map, of } from 'rxjs';
import { beforeEach, describe, expect, test } from 'vitest';

Check warning on line 2 in packages/operators/src/fetch/autoPagination.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'expect' is defined but never used

import { log } from '../log';
import { autoPagination } from './autoPagination';
import { resolveJSON } from './resolve';

Expand All @@ -26,16 +27,15 @@ describe('auto pagination', function () {
}
}
}),
log(false),
resolveJSON(),
log(false),
map(({ products }) => products),
concatAll()
)
.subscribe({
next: e => console.log(e),

Check warning on line 37 in packages/operators/src/fetch/autoPagination.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
complete: () => {
console.log('COMPLETE');
done();
}
complete: () => done()
});
});
});
Expand Down
5 changes: 1 addition & 4 deletions packages/operators/src/fetch/concurrentDownload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ describe('multi fetch', function () {
)
.subscribe({
next: e => console.log(e),

Check warning on line 32 in packages/operators/src/fetch/concurrentDownload.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
complete: () => {
console.log('COMPLETE');
done();
}
complete: () => done()
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/operators/src/fetch/download.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fetchMock from 'fetch-mock';
import { of } from 'rxjs';
import { afterEach, test, describe, beforeEach, expect } from 'vitest';

import { log } from '../log.js';
import { download, downloadJSON } from './download.js';

Check warning on line 6 in packages/operators/src/fetch/download.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'download' is defined but never used

describe('download operator', function () {
Expand All @@ -27,13 +28,12 @@ describe('download operator', function () {
test('successfull download', () =>
new Promise(done => {
of('https://httpbin.org/my-url-fast')
.pipe(downloadJSON())
.pipe(downloadJSON(), log(false))
.subscribe({
next: data => {
expect(data).deep.equal({ hello: 'fast world' });
done();
},
complete: e => console.log('COMPLETE', e)
complete: e => done()

Check warning on line 36 in packages/operators/src/fetch/download.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'e' is defined but never used
});
}));
});
4 changes: 2 additions & 2 deletions packages/operators/src/fetch/lazyPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { concatMap, map } from 'rxjs';

import { concurrentDownload } from './concurrentDownload';

export const lazyPagination = ({ createRoute }) => {
export const lazyPagination = ({ resolveRoute }) => {
return source =>
source.pipe(
concatMap(({ url, pager, concurrent }) => {
return pager.pipe(
map(options => createRoute(url, options)),
map(options => resolveRoute(url, options)),
concurrentDownload(concurrent)
);
})
Expand Down
13 changes: 7 additions & 6 deletions packages/operators/src/fetch/lazyPagination.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { concatAll, map, of, Subject } from 'rxjs';
import { beforeEach, describe, expect, test } from 'vitest';

Check warning on line 2 in packages/operators/src/fetch/lazyPagination.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

'expect' is defined but never used

import { log } from '../log';
import { lazyPagination } from './lazyPagination';
import { resolveJSON } from './resolve';

Expand All @@ -16,24 +17,24 @@ describe('lazy pagination operator', function () {
of({ url: new URL('https://dummyjson.com/products'), pager, concurrent: 4 })
.pipe(
lazyPagination({
createRoute: (url, { value, limit = 10 }) => {
resolveRoute: (url, { value, limit = 10 }) => {
const newUrl = new URL(`${url}`);
newUrl.searchParams.set('skip', value * limit);
newUrl.searchParams.set('limit', limit);
newUrl.searchParams.set('select', 'title,price');
return newUrl;
}
}),
log(false),
resolveJSON(),
log(false),
map(({ products }) => products),
concatAll()
concatAll(),
log(false)
)
.subscribe({
next: e => console.log(e),

Check warning on line 36 in packages/operators/src/fetch/lazyPagination.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
complete: () => {
console.log('COMPLETE');
done();
}
complete: () => done()
});

pager.next({ value: 2 });
Expand Down
32 changes: 16 additions & 16 deletions packages/operators/src/fetch/polling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ describe('polling', function () {
});

test('auto polling', async function () {
of({ url: new URL('https://dummyjson.com/products') })
.pipe(
polling({
validateResult: data => {
return data.total > data.skip + data.limit;
}
})
// map(({ data: { products } }) => products),
// concatAll()
)
.subscribe({
next: e => console.log('aha'),
complete: () => console.log('COMPLETE')
});

await new Promise(resolve => setTimeout(resolve, 5000));
return new Promise(done => {
of({ url: new URL('https://dummyjson.com/products') })
.pipe(
polling({
validateResult: data => {
return data.total > data.skip + data.limit;
}
})
// map(({ data: { products } }) => products),
// concatAll()
)
.subscribe({
next: e => console.log('aha'),
complete: () => done()
});
});
});
});
3 changes: 2 additions & 1 deletion packages/operators/src/fetch/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fetchMock from 'fetch-mock';
import { of } from 'rxjs';
import { afterEach, test, describe, beforeEach, expect } from 'vitest';

import { log } from '../log.js';
import { request } from './request.js';

describe('request observable with default operators', function () {
Expand All @@ -26,7 +27,7 @@ describe('request observable with default operators', function () {
test('successfull request', () =>
new Promise(done => {
of('https://httpbin.org/my-url-fast')
.pipe(request())
.pipe(request(), log(false))
.subscribe({
next: resp => {
expect(resp).deep.includes({ ok: true });
Expand Down
12 changes: 7 additions & 5 deletions packages/operators/src/fetch/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ describe('request observable with default operators', function () {
return new Promise(done => {
of(req)
.pipe(upload(), log(false), resolveJSON(), log(false))
.subscribe(e => {
expect(e)
.deep.includes({ originalname: 'test_image.jpg' })
.have.all.keys('filename', 'location');
done();
.subscribe({
next: e => {
expect(e)
.deep.includes({ originalname: 'test_image.jpg' })
.have.all.keys('filename', 'location');
},
complete: () => done()
});
});
});
Expand Down

0 comments on commit 3d20b2e

Please sign in to comment.