Skip to content

Commit

Permalink
chore: add test for decimal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Nov 27, 2022
1 parent 1104b42 commit d7789de
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/collections/simple_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Collections.SimpleTest do
collection "tasks" do
attribute :name, String.t(), default: "Fix errors"
attribute :status, integer(), derived: true
attribute :sequence_id, BSON.Decimal128.t(), default: Decimal.new(0)
after_load &Task.after_load/1
end

Expand Down Expand Up @@ -116,6 +117,17 @@ defmodule Collections.SimpleTest do
assert %Card{intro: "new intro", label: %Label{color: :red, name: "warning"}} = struct_card
end

test "dump decimal attributes", c do
alias Collections.SimpleTest.Task

task = %Task{Task.new() | sequence_id: Decimal.new(123)}
assert :ok = Task.insert_one(task, c.pid)

task = Task.find_one(task._id, c.pid)
assert task.sequence_id != Decimal.new(0)
assert task.sequence_id == Decimal.new(123)
end

test "dump derived attributes", c do
alias Collections.SimpleTest.Task
task = %Task{Task.new() | status: :red}
Expand Down

0 comments on commit d7789de

Please sign in to comment.