mercredi 2 décembre 2020

Rails Test Expects NIL

So I am writing a unit test to test whether a contact is blocked... if it is blocked then I expect the contact to be unable to send a message.

    test 'whatsapp blocked contact dont receive message' do
        account = accounts(:smooch_whatsapp)
        
        ActsAsTenant.with_tenant(account) do
            blocked_contact = contacts(:whatsapper)
            blocked_contact.blocked = true
            blocked_contact.save!
            
            before = Conversation.where(account: account).count
            
            payload[:format] = "json"
            post smooch_messages_path, params: payload
            assert_response :success

            after = Conversation.where(account: account).count

            message = Message.find_by(external_id: "b1f2003cd817cd4d6faf8285")
            assert_nil message
            assert_equal before, after
        end
    end

the test keeps failing because it expects the message to be nil if the contact is blocked

Expected #<Message id: 1030097468, text: "Hi", message_type: "Text", contact_id: 973852195, created_at: "2020-12-03 01:00:13", updated_at: "2020-12-03 01:00:13",image_file_size: nil whatsapp_message_id: nil, direction: "IN",  word_processed: false, read_timestamp: nil, external_id: "5cf0ee1c2c9d37000"> to be nil.

how do I fix it??

Aucun commentaire:

Enregistrer un commentaire