-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ensure our enums are types and values (#3146)
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { expectAssignable, expectType } from 'tsd'; | ||
|
||
import { | ||
AuthMechanism, | ||
AutoEncryptionLoggerLevel, | ||
BatchType, | ||
BSONType, | ||
Compressor, | ||
CURSOR_FLAGS, | ||
CursorFlag, | ||
ExplainVerbosity, | ||
GSSAPICanonicalizationValue, | ||
LoggerLevel, | ||
ProfilingLevel, | ||
ReadConcernLevel, | ||
ReadPreferenceMode, | ||
ReturnDocument, | ||
ServerApiVersion, | ||
ServerType, | ||
TopologyType | ||
} from '../../src/index'; | ||
|
||
const num: number = Math.random(); | ||
|
||
// In our index.ts we clump CURSOR_FLAGS with the enums but its an array | ||
expectType<CursorFlag>(CURSOR_FLAGS[num]); | ||
|
||
// Explain is kept as type string so we can automatically allow any new level to be passed through | ||
expectAssignable<string>(Object.values(ExplainVerbosity)[num]); | ||
|
||
// Note both the Enum name and a property on the enum are the same type | ||
// Object.values(x)[num] gets a union of the all the value types | ||
expectType<AuthMechanism>(Object.values(AuthMechanism)[num]); | ||
expectType<AutoEncryptionLoggerLevel>(Object.values(AutoEncryptionLoggerLevel)[num]); | ||
expectType<BatchType>(Object.values(BatchType)[num]); | ||
expectType<BSONType>(Object.values(BSONType)[num]); | ||
expectType<Compressor>(Object.values(Compressor)[num]); | ||
expectType<GSSAPICanonicalizationValue>(Object.values(GSSAPICanonicalizationValue)[num]); | ||
expectType<LoggerLevel>(Object.values(LoggerLevel)[num]); | ||
expectType<ProfilingLevel>(Object.values(ProfilingLevel)[num]); | ||
expectType<ReadConcernLevel>(Object.values(ReadConcernLevel)[num]); | ||
expectType<ReadPreferenceMode>(Object.values(ReadPreferenceMode)[num]); | ||
expectType<ReturnDocument>(Object.values(ReturnDocument)[num]); | ||
expectType<ServerApiVersion>(Object.values(ServerApiVersion)[num]); | ||
expectType<ServerType>(Object.values(ServerType)[num]); | ||
expectType<TopologyType>(Object.values(TopologyType)[num]); |