I have such cases:
stock status can be in stock
, undefined
(there is no such field in the object) or any other text
stock status is true if it is 'in stock' or undefined all others are false
so this is my test object
obj =
one:
stock: 'in stock'
two:
some: 'x'
three:
stock: 'not in stock blah blah any other text'
my method
stockCheck = (stock, msg) ->
console.log {msg}
return true if !stock or stock == 'in stock'
and some simply test
console.log stockCheck(obj.one.stock)?, 'should be in stock'
console.log stockCheck(obj.two.stock)?, 'should be in stock'
console.log stockCheck(obj.three.stock)?, 'should not be in stock'
is my code well for such cases?