Skip to content

Commit

Permalink
fix: Remove uuid usage
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio committed Oct 13, 2023
1 parent 54be05d commit 3fdfbdc
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/entities/Proposal/testHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable @typescript-eslint/no-explicit-any
import crypto from 'crypto'
import JobContext from 'decentraland-gatsby/dist/entities/Job/context'
import { v1 as uuid } from 'uuid'

import Time from '../../utils/date/Time'
import { Budget } from '../Budget/types'
Expand Down Expand Up @@ -103,7 +103,7 @@ export function createTestProposal(
grantCategory?: NewGrantCategory
): ProposalAttributes {
const testProposalConfiguration = getTestProposalConfiguration(proposalType, grantSize, grantCategory)
const id = uuid()
const id = crypto.randomUUID()
return {
...BASIC_ATTRIBUTES,
id: `id-${proposalType.toString()}-${proposalStatus.toString()}-${id}`,
Expand Down
4 changes: 2 additions & 2 deletions src/entities/QuarterBudget/model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from 'crypto'
import { Model } from 'decentraland-gatsby/dist/entities/Database/model'
import { SQL, table } from 'decentraland-gatsby/dist/entities/Database/utils'
import snakeCase from 'lodash/snakeCase'
import { v1 as uuid } from 'uuid'

import { TransparencyBudget } from '../../clients/DclData'
import Time from '../../utils/date/Time'
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class QuarterBudgetModel extends Model<QuarterBudgetAttributes> {

private static getNewQuarterBudget(transparencyBudget: TransparencyBudget, startAt: Date, finishAt: Date, now: Date) {
const newQuarterBudget: QuarterBudgetAttributes = {
id: uuid(),
id: crypto.randomUUID(),
total: transparencyBudget.total,
start_at: startAt,
finish_at: finishAt,
Expand Down
6 changes: 2 additions & 4 deletions src/entities/Updates/model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { def } from 'bdd-lazy-var/getter'
import * as uuid from 'uuid'
import crypto from 'crypto'

import Time from '../../utils/date/Time'
import { getMonthsBetweenDates } from '../../utils/date/getMonthsBetweenDates'
Expand All @@ -8,8 +8,6 @@ import { VestingStartDate } from '../Grant/types'
import UpdateModel from './model'
import { UpdateStatus } from './types'

jest.mock('uuid')

const PROPOSAL_ID = '123'
const UUID = '00000000-0000-0000-0000-000000000000'

Expand All @@ -20,7 +18,7 @@ describe('UpdateModel', () => {
jest.clearAllMocks()
jest.spyOn(UpdateModel, 'createMany').mockImplementation((list: any) => list)
jest.spyOn(UpdateModel, 'delete').mockResolvedValue([] as any)
jest.spyOn(uuid, 'v1').mockReturnValue(UUID)
jest.spyOn(crypto, 'randomUUID').mockReturnValue(UUID)
jest.useFakeTimers('modern')
jest.setSystemTime(FAKE_NOW)
})
Expand Down
6 changes: 3 additions & 3 deletions src/entities/Updates/model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto from 'crypto'
import { Model } from 'decentraland-gatsby/dist/entities/Database/model'
import { v1 as uuid } from 'uuid'

import { VestingDates } from '../../clients/VestingData'
import Time from '../../utils/date/Time'
Expand Down Expand Up @@ -31,7 +31,7 @@ export default class UpdateModel extends Model<UpdateAttributes> {

const updates = Array.from(Array(updatesQuantity), (_, index) => {
const update: UpdateAttributes = {
id: uuid(),
id: crypto.randomUUID(),
proposal_id: proposalId,
status: UpdateStatus.Pending,
due_date: this.getDueDate(firstUpdateStartingDate, index),
Expand Down Expand Up @@ -68,7 +68,7 @@ export default class UpdateModel extends Model<UpdateAttributes> {
const now = new Date()

return await this.create({
id: uuid(),
id: crypto.randomUUID(),
status: UpdateStatus.Done,
due_date: undefined,
completion_date: now,
Expand Down
6 changes: 3 additions & 3 deletions src/entities/Updates/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v1 as uuid } from 'uuid'
import crypto from 'crypto'

import Time from '../../utils/date/Time'

Expand All @@ -20,8 +20,8 @@ type GenerateUpdate = Pick<
| 'completion_date'
>
const generateUpdate = (update: GenerateUpdate): UpdateAttributes => ({
id: uuid(),
proposal_id: uuid(),
id: crypto.randomUUID(),
proposal_id: crypto.randomUUID(),
health: update.health,
introduction: update.introduction,
highlights: update.highlights,
Expand Down
4 changes: 2 additions & 2 deletions src/services/BadgesService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto from 'crypto'
import logger from 'decentraland-gatsby/dist/entities/Development/logger'
import { v1 as uuid } from 'uuid'

import AirdropJobModel from '../back/models/AirdropJob'
import { VoteService } from '../back/services/vote'
Expand Down Expand Up @@ -177,7 +177,7 @@ export class BadgesService {
private static async queueAirdropJob(badgeSpec: string, recipients: string[]) {
logger.log(`Enqueueing airdrop job`, { badgeSpec, recipients })
try {
await AirdropJobModel.create({ id: uuid(), badge_spec: badgeSpec, recipients })
await AirdropJobModel.create({ id: crypto.randomUUID(), badge_spec: badgeSpec, recipients })
} catch (error) {
ErrorService.report('Unable to create AirdropJob', {
error,
Expand Down
4 changes: 2 additions & 2 deletions src/services/ProposalService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from 'crypto'
import logger from 'decentraland-gatsby/dist/entities/Development/logger'
import RequestError from 'decentraland-gatsby/dist/entities/Route/error'
import { v1 as uuid } from 'uuid'

import { VoteService } from '../back/services/vote'
import { Discourse, DiscourseComment, DiscoursePost } from '../clients/Discourse'
Expand Down Expand Up @@ -44,7 +44,7 @@ export class ProposalService {
throw new Error('Decentraland DAO Grants Program has been put on hold')
}

const proposalId = uuid()
const proposalId = crypto.randomUUID()
const proposalLifespan = this.getLifespan(proposalInCreation)
const coAuthors = this.getCoAuthors(proposalInCreation)

Expand Down

0 comments on commit 3fdfbdc

Please sign in to comment.