From 71f4c51f8ab90ee1dea9779740ff28d60f8ad32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=A3=20Rinaldi?= Date: Mon, 28 Oct 2024 15:26:51 -0300 Subject: [PATCH] Move tests to separate file --- src/colection.distinct.assert.ts | 32 +++++++++++++++++++++++++++++ src/collection.assert.ts | 35 +------------------------------- 2 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 src/colection.distinct.assert.ts diff --git a/src/colection.distinct.assert.ts b/src/colection.distinct.assert.ts new file mode 100644 index 0000000..a78aa0e --- /dev/null +++ b/src/colection.distinct.assert.ts @@ -0,0 +1,32 @@ +import type { ObjectId } from 'mongodb' +import { TsReadWriteCollection } from './collection' +import * as ta from 'type-assertions' + +type DistinctSampleType = { + _id: ObjectId + str: string + nested: { + field: number + } +} + +type TestCollection = TsReadWriteCollection< + DistinctSampleType & { writeOnly: boolean }, + DistinctSampleType & { readOnly: boolean } +> + +const distinctString = (c: TestCollection) => c.distinct('str', {}) +const distinctId = (c: TestCollection) => c.distinct('_id', {}) +const distinctNested = (c: TestCollection) => c.distinct('nested.field', {}) +const distinctReadOnly = (c: TestCollection) => c.distinct('readOnly', {}) + +ta.assert>, string[]>>() +ta.assert>, ObjectId[]>>() +ta.assert>, number[]>>() +ta.assert>, boolean[]>>() + +// @ts-expect-error +const _distinctIncorrect = (c: TestCollection) => c.distinct('no', {}) + +// @ts-expect-error +const _distinctWriteOnly = (c: TestCollection) => c.distinct('writeOnly', {}) diff --git a/src/collection.assert.ts b/src/collection.assert.ts index 580df34..d0d2402 100644 --- a/src/collection.assert.ts +++ b/src/collection.assert.ts @@ -7,11 +7,7 @@ import type { WithId, } from 'mongodb' import * as ta from 'type-assertions' -import { - TsCollection, - TsReadCollection, - TsReadWriteCollection, -} from './collection' +import { TsCollection, TsReadCollection } from './collection' import type { TsFilter, TsFindOneAndDeleteOptions } from './types' type TSchema = { a: string; _id: ObjectId } @@ -87,32 +83,3 @@ ta.assert< > > >() - -type DistinctSampleType = { - _id: ObjectId - str: string - nested: { - field: number - } -} - -type TestCollection = TsReadWriteCollection< - DistinctSampleType & { writeOnly: boolean }, - DistinctSampleType & { readOnly: boolean } -> - -const distinctString = (c: TestCollection) => c.distinct('str', {}) -const distinctId = (c: TestCollection) => c.distinct('_id', {}) -const distinctNested = (c: TestCollection) => c.distinct('nested.field', {}) -const distinctReadOnly = (c: TestCollection) => c.distinct('readOnly', {}) - -ta.assert>, string[]>>() -ta.assert>, ObjectId[]>>() -ta.assert>, number[]>>() -ta.assert>, boolean[]>>() - -// @ts-expect-error -const _distinctIncorrect = (c: TestCollection) => c.distinct('no', {}) - -// @ts-expect-error -const _distinctWriteOnly = (c: TestCollection) => c.distinct('writeOnly', {})