Skip to content

Commit

Permalink
Merge pull request #2562 from specklesystems/alessandro/web-1533-fix-…
Browse files Browse the repository at this point in the history
…unique-values-in-seed

chore(seed): fix seed using library to generate unique values
  • Loading branch information
alemagio authored Aug 2, 2024
2 parents 2fb1ced + 221cd55 commit f5b262f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/server/modules/cli/commands/db/seed/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,36 @@ const { Users, ServerAcl } = require('@/modules/core/dbSchema')
const { Roles } = require('@/modules/core/helpers/mainConstants')
const { faker } = require('@faker-js/faker')
const { range } = require('lodash')
const { UniqueEnforcer } = require('enforce-unique')

const RETRY_COUNT = 3
const UNIQUE_MAX_TIME = 500

const uniqueEnforcer = new UniqueEnforcer()

function createFakeUser() {
return {
id: faker.unique(faker.random.alphaNumeric, [10], { maxTime: UNIQUE_MAX_TIME }),
name: faker.name.firstName() + ' ' + faker.name.lastName(),
id: uniqueEnforcer.enforce(() => faker.string.alphanumeric(10), {
maxTime: UNIQUE_MAX_TIME
}),
name: faker.person.firstName() + ' ' + faker.person.lastName(),
bio: faker.lorem.lines(5),
company: faker.company.companyName(),
email: faker.unique(
faker.internet.email,
[
faker.unique(faker.random.alphaNumeric, [10]),
faker.unique(faker.random.alphaNumeric, [10])
],
{ maxTime: UNIQUE_MAX_TIME }
company: faker.company.name(),
email: uniqueEnforcer.enforce(
() =>
faker.internet.email({
firstName: faker.string.alphanumeric(),
lastName: faker.string.alphanumeric()
}),
{
maxTime: UNIQUE_MAX_TIME,
maxRetries: RETRY_COUNT
}
),
verified: faker.datatype.boolean(),
avatar: faker.random.alphaNumeric(255),
avatar: faker.string.alphanumeric(255),
ip: faker.internet.ipv4(),
passwordDigest: faker.random.alphaNumeric(255)
passwordDigest: faker.string.alphanumeric(255)
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
"concurrently": "^7.0.0",
"cross-env": "^7.0.3",
"deep-equal-in-any-order": "^1.1.15",
"enforce-unique": "^1.3.0",
"eslint": "^8.11.0",
"eslint-config-prettier": "^8.5.0",
"http-proxy-middleware": "v3.0.0-beta.0",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15620,6 +15620,7 @@ __metadata:
deep-equal-in-any-order: "npm:^1.1.15"
dotenv: "npm:^8.2.0"
ejs: "npm:^3.1.8"
enforce-unique: "npm:^1.3.0"
eslint: "npm:^8.11.0"
eslint-config-prettier: "npm:^8.5.0"
eventemitter2: "npm:^6.4.7"
Expand Down Expand Up @@ -28386,6 +28387,13 @@ __metadata:
languageName: node
linkType: hard

"enforce-unique@npm:^1.3.0":
version: 1.3.0
resolution: "enforce-unique@npm:1.3.0"
checksum: 10/c92da297787ff17ac1671c5c86ddc075308fb895fc0d728d2860ce152d1ab2f7b04d5c41ba4b86e75175c723b70aaf7f3d282930ec464fff3a96d3d8ddcdb4ba
languageName: node
linkType: hard

"enhanced-resolve@npm:^4.1.1":
version: 4.5.0
resolution: "enhanced-resolve@npm:4.5.0"
Expand Down

0 comments on commit f5b262f

Please sign in to comment.