Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
test: test for no pagination instead of default pagination
  • Loading branch information
fratzinger committed Jan 9, 2022
commit 8c395f9aac4019a061adb77cf20db6b046fa48d2
4 changes: 2 additions & 2 deletions packages/adapter-tests/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type AdapterMethodsTestName =
'.remove + $select' |
'.remove + id + query' |
'.remove + multi' |
'.remove + multi default pagination' |
'.remove + multi no pagination' |
'.remove + id + query id' |
'.update' |
'.update + $select' |
Expand All @@ -40,7 +40,7 @@ export type AdapterMethodsTestName =
'.patch + $select' |
'.patch + id + query' |
'.patch multiple' |
'.patch multiple default pagination' |
'.patch multiple no pagination' |
'.patch multi query same' |
'.patch multi query changed' |
'.patch + NotFound' |
Expand Down
55 changes: 15 additions & 40 deletions packages/adapter-tests/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default (test: AdapterMethodsTest, app: any, _errors: any, serviceName: s
assert.ok(names.includes('David'), 'David removed');
});

test('.remove + multi default pagination', async () => {
test('.remove + multi no pagination', async () => {
try {
await service.remove(doug[idProp]);
} catch (error: any) {}
Expand All @@ -177,38 +177,23 @@ export default (test: AdapterMethodsTest, app: any, _errors: any, serviceName: s
'max': 100
};

let emptyItems = await service.find({ paginate: false });
assert.strictEqual(emptyItems.length, 0, 'no entries before')
const emptyItems = await service.find({ paginate: false });
assert.strictEqual(emptyItems.length, 0, 'no items before')

const createdItems = await service.create(
Array.from(Array(count)).map((_, i) => ({ name: `name-${i}`, age: 3, created: true }))
);
assert.strictEqual(createdItems.length, count, `created ${count} entries`);
assert.strictEqual(createdItems.length, count, `created ${count} items`);

let foundItems = await service.find({ paginate: false });
assert.strictEqual(foundItems.length, count, `created ${count} entries`);
const foundItems = await service.find({ paginate: false });
assert.strictEqual(foundItems.length, count, `created ${count} items`);

const foundPaginatedItems = await service.find({});
assert.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated data');

const data1 = await service.remove(null, { query: { created: true }, paginate: false });

assert.strictEqual(data1.length, count, `returned all ${ count } entries`);

emptyItems = await service.find({ paginate: false });
assert.strictEqual(emptyItems.length, 0, 'no entries before')

await service.create(
Array.from(Array(count)).map((_, i) => ({ name: `name-${i}`, age: 3, created: true }))
);

foundItems = await service.find({ paginate: false });
assert.strictEqual(foundItems.length, count, `created ${count} entries`);
assert.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated items');

const data2 = await service.remove(null, { query: { created: true } });

assert.strictEqual(data2.length, defaultPaginate, `returned paginated ${ defaultPaginate } entries`);
const allItems = await service.remove(null, { query: { created: true } });

assert.strictEqual(allItems.length, count, `removed all ${ count } items`);
} finally {
await service.remove(null, { query: { created: true }, paginate: false });

Expand Down Expand Up @@ -418,7 +403,7 @@ export default (test: AdapterMethodsTest, app: any, _errors: any, serviceName: s
await service.remove(david[idProp]);
});

test('.patch multiple default pagination', async () => {
test('.patch multiple no pagination', async () => {
try {
await service.remove(doug[idProp]);
} catch (error: any) {}
Expand All @@ -441,33 +426,23 @@ export default (test: AdapterMethodsTest, app: any, _errors: any, serviceName: s
};

const emptyItems = await service.find({ paginate: false });
assert.strictEqual(emptyItems.length, 0, 'no entries before')
assert.strictEqual(emptyItems.length, 0, 'no items before')

const createdItems = await service.create(
Array.from(Array(count)).map((_, i) => ({ name: `name-${i}`, age: 3, created: true }))
);
assert.strictEqual(createdItems.length, count, `created ${count} entries`);
assert.strictEqual(createdItems.length, count, `created ${count} items`);
ids = createdItems.map((item: any) => item[idProp]);

const foundItems = await service.find({ paginate: false });
assert.strictEqual(foundItems.length, count, `created ${count} entries`);
assert.strictEqual(foundItems.length, count, `created ${count} items`);

const foundPaginatedItems = await service.find({});
assert.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated data')

const allItems = await service.patch(null, { age: 4 }, { query: { created: true } })

const data1 = await service.patch(null, {
age: 4
}, { query: { created: true }, paginate: false })

assert.strictEqual(data1.length, count, `returned all ${ count } entries`);

const data2 = await service.patch(null, {
age: 2
}, { query: { created: true } });

assert.strictEqual(data2.length, defaultPaginate, `returned paginated ${ defaultPaginate } entries`);

assert.strictEqual(allItems.length, count, `patched all ${ count } items`);
} finally {
service.options.multi = multiBefore;
service.options.paginate = paginateBefore;
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-tests/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const testSuite = adapterTests([
'.remove + $select',
'.remove + id + query',
'.remove + multi',
'.remove + multi no pagination',
'.update',
'.update + $select',
'.update + id + query',
Expand All @@ -26,7 +27,7 @@ const testSuite = adapterTests([
'.patch + $select',
'.patch + id + query',
'.patch multiple',
'.patch multiple default pagination',
'.patch multiple no pagination',
'.patch multi query changed',
'.patch multi query same',
'.patch + NotFound',
Expand Down
4 changes: 2 additions & 2 deletions packages/memory/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const testSuite = adapterTests([
'.remove + $select',
'.remove + id + query',
'.remove + multi',
'.remove + multi default pagination',
'.remove + multi no pagination',
'.remove + id + query id',
'.update',
'.update + $select',
Expand All @@ -37,7 +37,7 @@ const testSuite = adapterTests([
'.patch + $select',
'.patch + id + query',
'.patch multiple',
'.patch multiple default pagination',
'.patch multiple no pagination',
'.patch multi query same',
'.patch multi query changed',
'.patch + query + NotFound',
Expand Down