gpt4 book ai didi

ruby-on-rails - 来自 Aws CognitoIdentityProvider 的 WebMock stub 数据

转载 作者:数据小太阳 更新时间:2023-10-29 08:11:08 25 4
gpt4 key购买 nike

我在 Rails Controller 关注点中有以下模块:

module AwsAuth
extend ActiveSupport::Concern

require 'aws-sdk'

def get_cognito_user(token)
cognitoidentityprovider = Aws::CognitoIdentityProvider::Client.new(region: ENV['AWS_REGION'])

begin
cognito_user = cognitoidentityprovider.get_user({ access_token: token })

puts cognito_user

return {"email" => cognito_user.username}

rescue StandardError => msg
puts "ERROR!"
puts msg
return {"error" => msg}
end
end
end

此时,将 cognito_user 返回:

#<Aws::CognitoIdentityProvider::Types::GetUserResponse:0x7fe51b0013a8
mfa_options = nil,
user_attributes = nil,
username = nil
>

我如何在 Rspec 中设置响应以使 username 和 user_attributes 不为 nil ?

最佳答案

在尝试了 yzalavin 的建议之后……以下对我有用……

allow_any_instance_of( AwsAuth )
.to receive(:get_cognito_user)
.and_return( JSON[ {email: "testy@example.com"}.to_json ] )

关于ruby-on-rails - 来自 Aws CognitoIdentityProvider 的 WebMock stub 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44450158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com