Skip to content

Commit

Permalink
jsdom adjustment for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Jul 19, 2019
1 parent baa730c commit 1a40e68
Show file tree
Hide file tree
Showing 4 changed files with 1,161 additions and 1,162 deletions.
31 changes: 16 additions & 15 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const chalk = require('ansi-colors');

export function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
module.exports = {
generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);

return v.toString(16);
});
}
return v.toString(16);
});
},
primaryKeyTypeSafetyCheck(targetPrimaryKeyType, primaryKey, modelName) {
const primaryKeyType = typeof primaryKey;

export function primaryKeyTypeSafetyCheck(targetPrimaryKeyType, primaryKey, modelName) {
const primaryKeyType = typeof primaryKey;
if (targetPrimaryKeyType === 'id' && (primaryKeyType !== 'number')) {
throw new Error(chalk.red(`[MemServer] ${modelName} model primaryKey type is 'id'. Instead you've tried to enter id: ${primaryKey} with ${primaryKeyType} type`));
} else if (targetPrimaryKeyType === 'uuid' && (primaryKeyType !== 'string')) {
throw new Error(chalk.red(`[MemServer] ${modelName} model primaryKey type is 'uuid'. Instead you've tried to enter uuid: ${primaryKey} with ${primaryKeyType} type`));
}

if (targetPrimaryKeyType === 'id' && (primaryKeyType !== 'number')) {
throw new Error(chalk.red(`[MemServer] ${modelName} model primaryKey type is 'id'. Instead you've tried to enter id: ${primaryKey} with ${primaryKeyType} type`));
} else if (targetPrimaryKeyType === 'uuid' && (primaryKeyType !== 'string')) {
throw new Error(chalk.red(`[MemServer] ${modelName} model primaryKey type is 'uuid'. Instead you've tried to enter uuid: ${primaryKey} with ${primaryKeyType} type`));
return targetPrimaryKeyType;
}

return targetPrimaryKeyType;
}
};
Loading

0 comments on commit 1a40e68

Please sign in to comment.