Sha256: 259f65c1f0e859879b90da386a96c53fe74511834c39fdeaf8c01f7f95d1440a

Contents?: true

Size: 1.98 KB

Versions: 13

Compression:

Stored size: 1.98 KB

Contents

#!/usr/bin/env ruby
# XXX XXX XXX XXX XXX XXX XXX   Warning!  XXX XXX XXX XXX XXX XXX XXX XXX XXX
#
# This *will* write to NetSuite, and delete things. If there is a bug here, we
# will probably leave things behind, accidentaly delete important production
# data and generally break shit.
#
# So, in summary, don't run this anywhere you mind losing data.
#
# XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX

$: << File.join(
		File.dirname(__FILE__),
			'..', 'lib'
)

require 'ns_connector'
require 'rspec/autorun'

unless ARGV.size == 1 then
	warn "Usage: #{$0} <config as ruby code>"
	warn "Warning! This script will probably destroy production data, "\
		"it is only intended for testing"
end

# We shift the argument off here, or it gets passed to the RSpec runner
NSConnector::Config.set_config!(eval(ARGV.shift))

def customer_id
	NSConnector::Config[:valid_customer_id]
end

def delete_id id
	NSConnector::Restlet.execute!(
		:action => 'delete',
		:type_id => 'contact',
		:fields => ['id'],
		:data => {
			:id => id
		}
	)
end

describe 'create' do
	it 'returns the saved record' do
		resource = NSConnector::Restlet.execute!(
			:action => 'create',
			:type_id => 'contact',
			:fields => ['id', 'firstname'],
			:data => {
				:firstname => '__test__'
			}
		)

		# Cleanup
		at_exit do
			warn "Cleaning up contact id: #{resource['id']}"
			delete_id(resource['id'])
		end

		expect(resource).to be_a(Hash)
		expect(resource['id']).to be_a(String)
		expect(resource['id']).to_not be_empty
		expect(resource['firstname']).to eql('__test__') 
	end
end

describe 'update' do
	it 'returns the updated record' do
		resource = NSConnector::Restlet.execute!(
			:action => 'update',
			:type_id => 'contact',
			:fields => ['id', 'firstname'],
			:data => {
				:id => customer_id,
				:firstname => 'Testguy'
			}
		)

		expect(resource).to be_a(Hash)
		expect(resource['id']).to be_a(String)
		expect(resource['id']).to_not be_empty
		expect(resource['firstname']).to eql('Testguy')
	end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ns_connector-0.1.0 support/super_dangerous_write_test
ns_connector-0.0.17 support/super_dangerous_write_test
ns_connector-0.0.16 support/super_dangerous_write_test
ns_connector-0.0.15 support/super_dangerous_write_test
ns_connector-0.0.14 support/super_dangerous_write_test
ns_connector-0.0.13 support/super_dangerous_write_test
ns_connector-0.0.12 support/super_dangerous_write_test
ns_connector-0.0.11 support/super_dangerous_write_test
ns_connector-0.0.10 support/super_dangerous_write_test
ns_connector-0.0.9 support/super_dangerous_write_test
ns_connector-0.0.8 support/super_dangerous_write_test
ns_connector-0.0.7 support/super_dangerous_write_test
ns_connector-0.0.6 support/super_dangerous_write_test