mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-10 07:55:21 +02:00
Update test fixtures and configurations for AI chat functionality
- Add family association to chat fixtures and tests - Set consistent password digest for test users - Enable AI for test users - Add OpenAI access token for test environment - Update chat and user model tests to include family context
This commit is contained in:
parent
7fdce5ce64
commit
51ff75df3a
6 changed files with 23 additions and 13 deletions
|
@ -3,6 +3,7 @@ require "test_helper"
|
|||
class ChatsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = users(:family_admin)
|
||||
@family = families(:dylan_family)
|
||||
sign_in @user
|
||||
end
|
||||
|
||||
|
@ -31,14 +32,14 @@ class ChatsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "should show chat" do
|
||||
chat = Chat.create!(user: @user, title: "Test Chat")
|
||||
chat = Chat.create!(user: @user, title: "Test Chat", family: @family)
|
||||
|
||||
get chat_url(chat)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should destroy chat" do
|
||||
chat = Chat.create!(user: @user, title: "Test Chat")
|
||||
chat = Chat.create!(user: @user, title: "Test Chat", family: @family)
|
||||
|
||||
assert_difference("Chat.count", -1) do
|
||||
delete chat_url(chat)
|
||||
|
@ -49,7 +50,7 @@ class ChatsControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
test "should not allow access to other user's chats" do
|
||||
other_user = users(:family_member)
|
||||
other_chat = Chat.create!(user: other_user, title: "Other User's Chat")
|
||||
other_chat = Chat.create!(user: other_user, title: "Other User's Chat", family: @family)
|
||||
|
||||
get chat_url(other_chat)
|
||||
assert_response :not_found
|
||||
|
@ -59,7 +60,7 @@ class ChatsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "should clear chat" do
|
||||
chat = Chat.create!(user: @user, title: "Test Chat")
|
||||
chat = Chat.create!(user: @user, title: "Test Chat", family: @family)
|
||||
system_message = chat.messages.create!(role: "system", content: "System prompt", internal: true)
|
||||
user_message = chat.messages.create!(role: "user", content: "User message", user: @user)
|
||||
|
||||
|
|
2
test/fixtures/chats.yml
vendored
2
test/fixtures/chats.yml
vendored
|
@ -3,7 +3,9 @@
|
|||
one:
|
||||
title: First Chat
|
||||
user: family_admin
|
||||
family: dylan_family
|
||||
|
||||
two:
|
||||
title: Second Chat
|
||||
user: family_member
|
||||
family: dylan_family
|
||||
|
|
17
test/fixtures/users.yml
vendored
17
test/fixtures/users.yml
vendored
|
@ -3,34 +3,38 @@ empty:
|
|||
first_name: User
|
||||
last_name: One
|
||||
email: user1@email.com
|
||||
password_digest: <%= BCrypt::Password.create('password') %>
|
||||
password_digest: $2a$12$K0ByB.6YI2/OYrB4fQOAb.62EWV9C4rm/S1DSzrfLtswVr7eOiLYa
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
ai_enabled: true
|
||||
|
||||
maybe_support_staff:
|
||||
family: empty
|
||||
first_name: Support
|
||||
last_name: Admin
|
||||
email: support@maybefinance.com
|
||||
password_digest: <%= BCrypt::Password.create('password') %>
|
||||
password_digest: $2a$12$K0ByB.6YI2/OYrB4fQOAb.62EWV9C4rm/S1DSzrfLtswVr7eOiLYa
|
||||
role: super_admin
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
ai_enabled: true
|
||||
|
||||
family_admin:
|
||||
family: dylan_family
|
||||
first_name: Bob
|
||||
last_name: Dylan
|
||||
email: bob@bobdylan.com
|
||||
password_digest: <%= BCrypt::Password.create('password') %>
|
||||
password_digest: $2a$12$K0ByB.6YI2/OYrB4fQOAb.62EWV9C4rm/S1DSzrfLtswVr7eOiLYa
|
||||
role: admin
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
ai_enabled: true
|
||||
|
||||
family_member:
|
||||
family: dylan_family
|
||||
first_name: Jakob
|
||||
last_name: Dylan
|
||||
email: jakobdylan@yahoo.com
|
||||
password_digest: <%= BCrypt::Password.create('password') %>
|
||||
password_digest: $2a$12$K0ByB.6YI2/OYrB4fQOAb.62EWV9C4rm/S1DSzrfLtswVr7eOiLYa
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
ai_enabled: true
|
||||
|
||||
new_email:
|
||||
family: empty
|
||||
|
@ -38,5 +42,6 @@ new_email:
|
|||
last_name: User
|
||||
email: user@example.com
|
||||
unconfirmed_email: new@example.com
|
||||
password_digest: <%= BCrypt::Password.create('password123') %>
|
||||
onboarded_at: <%= Time.current %>
|
||||
password_digest: $2a$12$K0ByB.6YI2/OYrB4fQOAb.62EWV9C4rm/S1DSzrfLtswVr7eOiLYa
|
||||
onboarded_at: <%= Time.current %>
|
||||
ai_enabled: true
|
|
@ -55,7 +55,8 @@ class Ai::FinancialAssistantTest < ActiveSupport::TestCase
|
|||
]
|
||||
}
|
||||
|
||||
result = @financial_assistant.send(:process_response, response, "Test question")
|
||||
messages = []
|
||||
result = @financial_assistant.send(:process_response, response, "Test question", messages)
|
||||
assert_equal "This is a direct response.", result
|
||||
end
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ require "test_helper"
|
|||
|
||||
class ChatTest < ActiveSupport::TestCase
|
||||
test "should not save chat without title" do
|
||||
chat = Chat.new(user: users(:family_admin))
|
||||
chat = Chat.new(user: users(:family_admin), family: families(:dylan_family))
|
||||
assert_not chat.save, "Saved the chat without a title"
|
||||
end
|
||||
|
||||
test "should save valid chat" do
|
||||
chat = Chat.new(title: "Test Chat", user: users(:family_admin))
|
||||
chat = Chat.new(title: "Test Chat", user: users(:family_admin), family: families(:dylan_family))
|
||||
assert chat.save, "Could not save valid chat"
|
||||
end
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ end
|
|||
require_relative "../config/environment"
|
||||
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
ENV["OPENAI_ACCESS_TOKEN"] ||= "test_openai_token"
|
||||
|
||||
# Fixes Segfaults on M1 Macs when running tests in parallel (temporary workaround)
|
||||
# https://github.com/ged/ruby-pg/issues/538#issuecomment-1591629049
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue