spec/netsuite/configuration_spec.rb in netsuite-0.5.7 vs spec/netsuite/configuration_spec.rb in netsuite-0.5.8

- old
+ new

@@ -62,24 +62,51 @@ end end end describe '#auth_header' do - before do - config.email = 'user@example.com' - config.password = 'myPassword' - config.account = 1234 + context 'when doing user authentication' do + before do + config.account = 1234 + config.email = 'user@example.com' + config.password = 'myPassword' + end + + it 'returns a hash representation of the authentication header' do + expect(config.auth_header).to eql({ + 'platformMsgs:passport' => { + 'platformCore:account' => '1234', + 'platformCore:email' => 'user@example.com', + 'platformCore:password' => 'myPassword', + 'platformCore:role' => { :@internalId => '3' }, + } + }) + end end - it 'returns a hash representation of the authentication header' do - expect(config.auth_header).to eql({ - 'platformMsgs:passport' => { - 'platformCore:email' => 'user@example.com', - 'platformCore:password' => 'myPassword', - 'platformCore:account' => '1234', - 'platformCore:role' => { :@internalId => '3' }, - } - }) + context 'when doing token authentication' do + before do + config.account = 1234 + config.consumer_key = 'consumer_key' + config.consumer_secret = 'consumer_secret' + config.token_id = 'token_id' + config.token_secret = 'token_secret' + end + + it 'returns tokenPassport object' do + expect(config.auth_header.has_key?('platformMsgs:tokenPassport')).to be_truthy + end + + it 'returns proper elements of tokenPassport' do + expect(config.auth_header['platformMsgs:tokenPassport']['platformCore:account']).to eql('1234') + expect(config.auth_header['platformMsgs:tokenPassport']['platformCore:consumerKey']).to eql('consumer_key') + expect(config.auth_header['platformMsgs:tokenPassport']['platformCore:token']).to eql('token_id') + expect(config.auth_header['platformMsgs:tokenPassport'][:attributes!]).to eql({ 'platformCore:signature' => { 'algorithm' => 'HMAC-SHA256' } }) + + expect(config.auth_header['platformMsgs:tokenPassport'].has_key?('platformCore:nonce')).to be_truthy + expect(config.auth_header['platformMsgs:tokenPassport'].has_key?('platformCore:timestamp')).to be_truthy + expect(config.auth_header['platformMsgs:tokenPassport'].has_key?('platformCore:signature')).to be_truthy + end end end describe '#soap_header' do before do