Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ensure our enums are types and values #3146

Merged
merged 3 commits into from
Feb 18, 2022
Merged
Changes from all commits
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
47 changes: 47 additions & 0 deletions test/types/enum.test-d.ts
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]);