dify_client_test.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. require 'test_helper'
  2. require 'webmock/minitest'
  3. require 'json'
  4. require 'dify_client'
  5. class DifyClientTest < Minitest::Test
  6. def setup
  7. @api_key = 'YOUR_API_KEY'
  8. @client = DifyClient::Client.new(@api_key)
  9. end
  10. def test_update_api_key
  11. new_api_key = 'NEW_API_KEY'
  12. @client.update_api_key(new_api_key)
  13. assert_equal new_api_key, @client.instance_variable_get(:@api_key)
  14. end
  15. def test_get_application_parameters
  16. user = 'USER_ID'
  17. expected_response = {}
  18. stub_request(:get, "https://api.dify.ai/v1/parameters").
  19. with(
  20. body: {"user"=>"USER_ID"},
  21. headers: {
  22. 'Accept'=>'*/*',
  23. 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
  24. 'Authorization'=>'Bearer YOUR_API_KEY',
  25. 'Content-Type'=>'application/x-www-form-urlencoded',
  26. 'Responsetype'=>'json',
  27. 'User-Agent'=>'Ruby'
  28. }).
  29. to_return(status: 200, body: expected_response.to_json, headers: {})
  30. response = @client.get_application_parameters(user)
  31. assert_equal expected_response, response
  32. end
  33. end