Skip to content

Commit e2f189c

Browse files
Refactor some function names & comment lines.
1 parent 639afa9 commit e2f189c

File tree

7 files changed

+32
-38
lines changed

7 files changed

+32
-38
lines changed

test/document.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11285,8 +11285,8 @@ describe('document', function() {
1128511285
});
1128611286
});
1128711287

11288-
describe('Check if instance functions that is supplied in schema option is availabe (m0_0a)', function() {
11289-
it('should give an instance function back rather than undefined', function M0_0aModelJS() {
11288+
describe('Check if instance functions that is supplied in schema option is availabe', function() {
11289+
it('should give an instance function back rather than undefined', function ModelJS() {
1129011290
const testSchema = new mongoose.Schema({}, { methods: { instanceFn() { return 'Returned from DocumentInstanceFn'; } } });
1129111291
const TestModel = mongoose.model('TestModel', testSchema);
1129211292
const TestDocument = new TestModel({});

test/model.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8491,8 +8491,8 @@ describe('Model', function() {
84918491
});
84928492
});
84938493

8494-
describe('Check if statics functions that is supplied in schema option is availabe (m0_0a)', function() {
8495-
it('should give a static function back rather than undefined', function M0_0aModelJS() {
8494+
describe('Check if statics functions that is supplied in schema option is availabe', function() {
8495+
it('should give a static function back rather than undefined', function ModelJS() {
84968496
const testSchema = new mongoose.Schema({}, { statics: { staticFn() { return 'Returned from staticFn'; } } });
84978497
const TestModel = mongoose.model('TestModel', testSchema);
84988498
assert.equal(TestModel.staticFn(), 'Returned from staticFn');

test/query.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3964,7 +3964,9 @@ describe('Query', function() {
39643964
Model.create({ userName: 'test' }, function(error) {
39653965
assert.ifError(error);
39663966
Model.find().byUserName('test').exec(function(error, docs) {
3967-
assert.ifError(error);
3967+
if (error instanceof Error) {
3968+
return done(error);
3969+
}
39683970
assert.equal(docs.length, 1);
39693971
assert.equal(docs[0].userName, 'test');
39703972
done();

test/types/document.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Schema, model, Model, Document, Error, Types } from 'mongoose';
22
import { expectAssignable, expectError, expectType } from 'tsd';
33
import { autoTypedModel } from './models.test';
4-
import { M0_0aAutoTypedSchemaType } from './schema.test';
4+
import { AutoTypedSchemaType } from './schema.test';
55

66
const schema: Schema = new Schema({ name: { type: 'String', required: true }, address: new Schema({ city: { type: String, required: true } }) });
77

@@ -169,20 +169,17 @@ function gh11435() {
169169
});
170170
}
171171

172-
function m0_0aDocument() {
172+
function autoTypedDocument() {
173173
const AutoTypedModel = autoTypedModel();
174174
const AutoTypeModelInstance = new AutoTypedModel({ unExistProperty: 1, description: 2 });
175175

176-
expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(AutoTypeModelInstance.userName);
177-
expectType<M0_0aAutoTypedSchemaType['schema']['favoritDrink']>(AutoTypeModelInstance.favoritDrink);
178-
expectType<M0_0aAutoTypedSchemaType['schema']['favoritColorMode']>(AutoTypeModelInstance.favoritColorMode);
176+
expectType<AutoTypedSchemaType['schema']['userName']>(AutoTypeModelInstance.userName);
177+
expectType<AutoTypedSchemaType['schema']['favoritDrink']>(AutoTypeModelInstance.favoritDrink);
178+
expectType<AutoTypedSchemaType['schema']['favoritColorMode']>(AutoTypeModelInstance.favoritColorMode);
179179
expectType<number>(AutoTypeModelInstance.unExistProperty);
180180
expectType<number>(AutoTypeModelInstance.description);
181181

182-
/* -------------------------------------------------------------------------- */
183-
/* Document-Methods-tests */
184-
/* -------------------------------------------------------------------------- */
185-
186-
expectType<ReturnType<M0_0aAutoTypedSchemaType['methods']['instanceFn']>>(new AutoTypedModel().instanceFn());
182+
// Document-Methods-tests
183+
expectType<ReturnType<AutoTypedSchemaType['methods']['instanceFn']>>(new AutoTypedModel().instanceFn());
187184

188185
}

test/types/models.test.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Schema, Document, Model, Types, connection, model } from 'mongoose';
22
import { expectError, expectType } from 'tsd';
3-
import { M0_0aAutoTypedSchemaType, autoTypedSchema } from './schema.test';
3+
import { AutoTypedSchemaType, autoTypedSchema } from './schema.test';
44

55
function conventionalSyntax(): void {
66
interface ITest extends Document {
@@ -219,31 +219,26 @@ export function autoTypedModel() {
219219
const AutoTypedModel = model('AutoTypeModel', AutoTypedSchema);
220220

221221
(async() => {
222-
/* -------------------------------------------------------------------------- */
223-
/* Model-functions-test */
224-
/* -------------------------------------------------------------------------- */
222+
// Model-functions-test
225223
// Create should works with arbitrary objects.
226224
const randomObject = await AutoTypedModel.create({ unExistKey: 'unExistKey', description: 'st' });
227225
expectType<string>(randomObject.unExistKey);
228-
expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(randomObject.userName);
226+
expectType<AutoTypedSchemaType['schema']['userName']>(randomObject.userName);
229227

230228
const testDoc1 = await AutoTypedModel.create({ userName: 'M0_0a' });
231-
expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(testDoc1.userName);
232-
expectType<M0_0aAutoTypedSchemaType['schema']['description']>(testDoc1.description);
229+
expectType<AutoTypedSchemaType['schema']['userName']>(testDoc1.userName);
230+
expectType<AutoTypedSchemaType['schema']['description']>(testDoc1.description);
233231

234232
const testDoc2 = await AutoTypedModel.insertMany([{ userName: 'M0_0a' }]);
235-
expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(testDoc2[0].userName);
236-
expectType<M0_0aAutoTypedSchemaType['schema']['description'] | undefined>(testDoc2[0]?.description);
233+
expectType<AutoTypedSchemaType['schema']['userName']>(testDoc2[0].userName);
234+
expectType<AutoTypedSchemaType['schema']['description'] | undefined>(testDoc2[0]?.description);
237235

238236
const testDoc3 = await AutoTypedModel.findOne({ userName: 'M0_0a' });
239-
expectType<M0_0aAutoTypedSchemaType['schema']['userName'] | undefined>(testDoc3?.userName);
240-
expectType<M0_0aAutoTypedSchemaType['schema']['description'] | undefined>(testDoc3?.description);
237+
expectType<AutoTypedSchemaType['schema']['userName'] | undefined>(testDoc3?.userName);
238+
expectType<AutoTypedSchemaType['schema']['description'] | undefined>(testDoc3?.description);
241239

242-
/* -------------------------------------------------------------------------- */
243-
/* Model-statics-functions-test */
244-
/* -------------------------------------------------------------------------- */
245-
246-
expectType<ReturnType<M0_0aAutoTypedSchemaType['statics']['staticFn']>>(AutoTypedModel.staticFn());
240+
// Model-statics-functions-test
241+
expectType<ReturnType<AutoTypedSchemaType['statics']['staticFn']>>(AutoTypedModel.staticFn());
247242

248243
})();
249244
return AutoTypedModel;

test/types/queries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HydratedDocument, Schema, model, Document, Types, Query, Model, QueryWi
22
import { ObjectId } from 'mongodb';
33
import { expectError, expectType } from 'tsd';
44
import { autoTypedModel } from './models.test';
5-
import { M0_0aAutoTypedSchemaType } from './schema.test';
5+
import { AutoTypedSchemaType } from './schema.test';
66

77
interface QueryHelpers {
88
_byName(this: QueryWithHelpers<any, ITest, QueryHelpers>, name: string): QueryWithHelpers<Array<ITest>, ITest, QueryHelpers>;

test/types/schema.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,34 +461,34 @@ export function autoTypedSchema() {
461461
}, {
462462
statics: {
463463
staticFn() {
464-
expectType<Model<M0_0aAutoTypedSchemaType['schema']>>(this);
464+
expectType<Model<AutoTypedSchemaType['schema']>>(this);
465465
return 'Returned from staticFn' as const;
466466
}
467467
},
468468
methods: {
469469
instanceFn() {
470-
expectType<HydratedDocument<M0_0aAutoTypedSchemaType['schema']>>(this);
470+
expectType<HydratedDocument<AutoTypedSchemaType['schema']>>(this);
471471
return 'Returned from DocumentInstanceFn' as const;
472472
}
473473
},
474474
query: {
475475
byUserName(userName) {
476-
expectAssignable<Query<unknown, M0_0aAutoTypedSchemaType['schema']>>(this);
476+
expectAssignable<Query<unknown, AutoTypedSchemaType['schema']>>(this);
477477
return this.where({ userName });
478478
}
479479
}
480480
});
481481

482482
type InferredSchemaType = InferSchemaType<typeof AutoTypedSchema>;
483483

484-
expectType<M0_0aAutoTypedSchemaType['schema']>({} as InferredSchemaType);
484+
expectType<AutoTypedSchemaType['schema']>({} as InferredSchemaType);
485485

486-
expectError<M0_0aAutoTypedSchemaType['schema'] & { doesNotExist: boolean; }>({} as InferredSchemaType);
486+
expectError<AutoTypedSchemaType['schema'] & { doesNotExist: boolean; }>({} as InferredSchemaType);
487487

488488
return AutoTypedSchema;
489489
}
490490

491-
export type M0_0aAutoTypedSchemaType = {
491+
export type AutoTypedSchemaType = {
492492
schema: {
493493
userName: string;
494494
description?: string;

0 commit comments

Comments
 (0)