TSFoster/elm-uuid

Mocked Uuid feature

Closed this issue · 2 comments

veeso commented

Hi there,

would it be possible to have a function to use for testing purposes which returns a Uuid to create mocked data types? When we write unit tests we always have to deal with Maybe Uuid to create mocks which is really annoying.

Something like

mocked : Uuid
mocked =
    Uuid "00000000-0000-0000-0000-000000000000"

would work fine.

Thanks in advance

Hi veeso,

I don't want it to be possible to create an invalid UUID. You can create a valid v4 UUID like so:

-- 5b58931d-bb69-406d-81a9-7746c300838c
mocked: UUID
mocked =
    Tuple.first (Random.step UUID.generator (Random.initialSeed 12345))

Alternatively, there are already four UUIDs in the package you could use: UUID.dnsNamespace, UUID.urlNamespace, UUID.oidNamespace, and UUID.x500Namespace.

veeso commented

Ok, didn't know that.
Thank you!