American British Translator - Contradictory tasks?

I’m very close to completing the QA unit, but I’m puzzled by these two tests. If you recall, this project only requires two input fields to be used and sent: text and locale:

  • If one or more of the required fields is missing, return { error: 'Required field(s) missing' }.

  • If text is empty, return { error: 'No text to translate' }

I guess there’s something I’m overlooking (maybe text being empty is not the same as text being missing??) 'cause I haven’t found any other posts from users experiencing this same issue, but from what I understand, if the text field is missing, the app should return { error: 'Required field(s) missing' } because that’s what the first test says should happen if either of the required fields is missing… but it should also return { error: 'No text to translate' }, because text is missing/empty.

Whenever I get one test to pass, the other one fails. If I set my code to

if( !req.body.locale || !req.body.text ){
        res.send({error: "Required field(s) missing"});
        return
}
    
if( !req.body.text ){
        res.send({error: "No text to translate"});
        return
}

the first test passes, the second one reads:
[Error: expected 'Required field(s) missing' to equal 'No text to translate']

and If I set my code to

if( !req.body.locale ){
        res.send({error: "Required field(s) missing"});
        return
}
    
if( !req.body.text ){
        res.send({error: "No text to translate"});
        return
}

the second test will pass, but the first one obviously reads:
[Error: expected 'No text to translate' to equal 'Required field(s) missing']

Maybe there’s some silly thing I’m misinterpreting, but I’ve been going at this one for a while, tried several things, and just can’t figure it out. In my mind, these two tasks cancel each other. Do I have a concept error in regards to what it would mean for text to be missing and what it would mean for it to be empty?

maybe you need to change order?

one is asking for the field to be missing in the sent object, the other specifically for text: '' . If you check for the value to be falsey you can’t distinguish between the two

1 Like

Thank you, Ilenia.
Yes, I had also thought about that (text being supposed to be "") , but still couldn’t get it to work. I tried it again, I guess somewhat differently, and now it worked.

What I still don’t understand is: if the form can be sent without having entered anything in the text field (i.e: req.body.text: "" ), then what could a user possibly do that would cause the form to be sent without req.body.text ? In what use case would the app return { error: 'Required field(s) missing' } besides not having selected a locale (which is impossible to do anyway, as one option is always selected)