Practical scripting · 65 / 69
Make a workflow decision
YOUR TASK
Make this happen
A workflow decision is easier to test as a pure function. Route paid orders with stock to production, paid orders without stock to waiting, and unpaid orders to payment.
Read the cases in
lesson.test.lua, then choose Check solution to see what needs to change.Update
subject.luauntil every test passes. Keep the supplied tests unchanged.
Read the starter and tests
subject.lua
exports.route = function(paid: boolean, stock: number): string return "production" end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("payment comes first", function()
local s = subject.load()
t.expect(s.route(false, 5)):eq("payment")
end)
t.it("waits for stock", function()
local s = subject.load()
t.expect(s.route(true, 0)):eq("waiting")
end)
t.it("ready for production", function()
local s = subject.load()
t.expect(s.route(true, 5)):eq("production")
end)