Skip to content

Commit

Permalink
chore: fix tests and unmaintained package (closes #421)
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Apr 27, 2022
1 parent b2322ef commit b36b79d
Show file tree
Hide file tree
Showing 6 changed files with 3,369 additions and 2,930 deletions.
9 changes: 4 additions & 5 deletions template/app/controllers/web/my-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ async function update(ctx) {
ctx.state.user[config.userFields.changeEmailTokenExpiresAt] = dayjs()
.add(config.changeEmailTokenTimeoutMs, 'milliseconds')
.toDate();
ctx.state.user[
config.userFields.changeEmailToken
] = await cryptoRandomString.async({
length: 32
});
ctx.state.user[config.userFields.changeEmailToken] =
await cryptoRandomString.async({
length: 32
});
ctx.state.user[config.userFields.changeEmailNewAddress] = body.email;
}

Expand Down
30 changes: 12 additions & 18 deletions template/app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,29 +267,23 @@ User.methods.sendVerificationEmail = async function (ctx, reset = false) {
return this;

if (reset) {
this[config.userFields.verificationPinExpiresAt] = this[
`__${config.userFields.verificationPinExpiresAt}`
];
this[config.userFields.verificationPinSentAt] = this[
`__${config.userFields.verificationPinSentAt}`
];
this[config.userFields.verificationPin] = this[
`__${config.userFields.verificationPin}`
];
this[config.userFields.verificationPinExpiresAt] =
this[`__${config.userFields.verificationPinExpiresAt}`];
this[config.userFields.verificationPinSentAt] =
this[`__${config.userFields.verificationPinSentAt}`];
this[config.userFields.verificationPin] =
this[`__${config.userFields.verificationPin}`];
await this.save();
return this;
}

// store old values in case we have to reset
this[`__${config.userFields.verificationPinExpiresAt}`] = this[
config.userFields.verificationPinExpiresAt
];
this[`__${config.userFields.verificationPinSentAt}`] = this[
config.userFields.verificationPinSentAt
];
this[`__${config.userFields.verificationPin}`] = this[
config.userFields.verificationPin
];
this[`__${config.userFields.verificationPinExpiresAt}`] =
this[config.userFields.verificationPinExpiresAt];
this[`__${config.userFields.verificationPinSentAt}`] =
this[config.userFields.verificationPinSentAt];
this[`__${config.userFields.verificationPin}`] =
this[config.userFields.verificationPin];

const diff =
this[config.userFields.verificationPinExpiresAt] &&
Expand Down
2 changes: 1 addition & 1 deletion template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"del": "^6.0.0",
"email-templates": "^8.0.3",
"fast-safe-stringify": "^2.0.7",
"font-awesome-assets": "^0.0.8",
"font-awesome-assets": "^0.0.9",
"gemoji": "^6.1.0",
"github-markdown-css": "^4.0.0",
"hasha": "^5.2.2",
Expand Down
7 changes: 4 additions & 3 deletions template/test/_utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Necessary utils for testing
// Librarires required for testing
const MongodbMemoryServer = require('mongodb-memory-server').default;
const { MongoMemoryServer } = require('mongodb-memory-server');
const mongoose = require('mongoose');
const request = require('supertest');
const sinon = require('sinon');
Expand All @@ -11,12 +11,13 @@ const { factory, MongooseAdapter } = require('factory-girl');
const config = require('../config');
const { Users } = require('../app/models');

const mongod = new MongodbMemoryServer();
let mongod;
const adapter = new MongooseAdapter();

// create connection to mongoose before all tests
exports.before = async () => {
const uri = await mongod.getConnectionString();
mongod = await MongoMemoryServer.create();
const uri = mongod.getUri();
await mongoose.connect(uri);

factory.setAdapter(adapter);
Expand Down
7 changes: 4 additions & 3 deletions template/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Necessary utils for testing
// Librarires required for testing
const MongodbMemoryServer = require('mongodb-memory-server').default;
const { MongoMemoryServer } = require('mongodb-memory-server');
const mongoose = require('mongoose');
const request = require('supertest');
const { factory, MongooseAdapter } = require('factory-girl');
Expand All @@ -12,13 +12,14 @@ factory.setAdapter(new MongooseAdapter());
const config = require('../config');
const { Users } = require('../app/models');

const mongod = new MongodbMemoryServer();
let mongod;

//
// setup utilities
//
exports.setupMongoose = async () => {
const uri = await mongod.getConnectionString();
mongod = await MongoMemoryServer.create();
const uri = mongod.getUri();
await mongoose.connect(uri);
};

Expand Down
Loading

0 comments on commit b36b79d

Please sign in to comment.