go_import 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/bin/go-import +96 -0
  2. data/lib/go_import/csv_helper.rb +47 -0
  3. data/lib/go_import/email_helper.rb +10 -0
  4. data/lib/go_import/errors.rb +22 -0
  5. data/lib/go_import/excel_helper.rb +10 -0
  6. data/lib/go_import/global_phone.json +6571 -0
  7. data/lib/go_import/model/address.rb +61 -0
  8. data/lib/go_import/model/class_settings.rb +50 -0
  9. data/lib/go_import/model/coworker.rb +76 -0
  10. data/lib/go_import/model/coworker_reference.rb +33 -0
  11. data/lib/go_import/model/customfield.rb +87 -0
  12. data/lib/go_import/model/deal.rb +172 -0
  13. data/lib/go_import/model/deal_class_settings.rb +73 -0
  14. data/lib/go_import/model/deal_state.rb +15 -0
  15. data/lib/go_import/model/deal_status.rb +23 -0
  16. data/lib/go_import/model/deal_status_reference.rb +47 -0
  17. data/lib/go_import/model/deal_status_setting.rb +49 -0
  18. data/lib/go_import/model/documents.rb +51 -0
  19. data/lib/go_import/model/link.rb +70 -0
  20. data/lib/go_import/model/note.rb +97 -0
  21. data/lib/go_import/model/note_classification.rb +25 -0
  22. data/lib/go_import/model/organization.rb +219 -0
  23. data/lib/go_import/model/person.rb +151 -0
  24. data/lib/go_import/model/referencetosource.rb +46 -0
  25. data/lib/go_import/model/relation.rb +23 -0
  26. data/lib/go_import/model/rootmodel.rb +359 -0
  27. data/lib/go_import/model/settings.rb +61 -0
  28. data/lib/go_import/model/tag.rb +35 -0
  29. data/lib/go_import/model_helpers.rb +54 -0
  30. data/lib/go_import/phone_helper.rb +74 -0
  31. data/lib/go_import/roo_helper.rb +80 -0
  32. data/lib/go_import/serialize_helper.rb +186 -0
  33. data/lib/go_import/source.rb +87 -0
  34. data/lib/go_import/templating.rb +52 -0
  35. data/lib/go_import.rb +19 -0
  36. data/sources/csv/.gitignore +14 -0
  37. data/sources/csv/.go_import/runner.rb +62 -0
  38. data/sources/csv/Gemfile +5 -0
  39. data/sources/csv/Rakefile.rb +7 -0
  40. data/sources/csv/converter.rb +179 -0
  41. data/sources/csv/data/coworkers.csv +2 -0
  42. data/sources/csv/data/deals.csv +2 -0
  43. data/sources/csv/data/organizations.csv +2 -0
  44. data/sources/csv/data/persons.csv +2 -0
  45. data/sources/csv/spec/exporter_spec.rb +17 -0
  46. data/sources/csv/spec/sample_data/coworkers.csv +2 -0
  47. data/sources/csv/spec/sample_data/deals.csv +2 -0
  48. data/sources/csv/spec/sample_data/organizations.csv +2 -0
  49. data/sources/csv/spec/sample_data/persons.csv +2 -0
  50. data/sources/csv/spec/spec_helper.rb +30 -0
  51. data/sources/easy/.gitignore +14 -0
  52. data/sources/easy/.go_import/runner.rb +115 -0
  53. data/sources/easy/Export/readme.txt +6 -0
  54. data/sources/easy/Gemfile +5 -0
  55. data/sources/easy/Rakefile.rb +7 -0
  56. data/sources/easy/converter.rb +435 -0
  57. data/sources/easy/spec/exporter_spec.rb +10 -0
  58. data/sources/easy/spec/sample_data/Company.txt +649 -0
  59. data/sources/easy/spec/spec_helper.rb +30 -0
  60. data/sources/excel/.gitignore +14 -0
  61. data/sources/excel/.go_import/runner.rb +116 -0
  62. data/sources/excel/Gemfile +6 -0
  63. data/sources/excel/Rakefile.rb +7 -0
  64. data/sources/excel/converter.rb +130 -0
  65. data/sources/excel/spec/sample_data/sample.xlsx +0 -0
  66. data/sources/excel/spec/spec_helper.rb +26 -0
  67. data/sources/excel/spec/tomodel_spec.rb +18 -0
  68. data/sources/excel/template.xlsx +0 -0
  69. data/spec/address_spec.rb +49 -0
  70. data/spec/class_settings_spec.rb +37 -0
  71. data/spec/coworker_spec.rb +94 -0
  72. data/spec/custom_field_spec.rb +22 -0
  73. data/spec/deal_class_settings_spec.rb +104 -0
  74. data/spec/deal_spec.rb +182 -0
  75. data/spec/deal_status_reference_spec.rb +17 -0
  76. data/spec/documents_spec.rb +37 -0
  77. data/spec/helpers/csv_helper_spec.rb +29 -0
  78. data/spec/helpers/email_helper_spec.rb +32 -0
  79. data/spec/helpers/phone_helper_spec.rb +97 -0
  80. data/spec/helpers/roo_helper_spec.rb +10 -0
  81. data/spec/helpers/serialize_helper_spec.rb +249 -0
  82. data/spec/helpers/xsd_validate_spec.rb +55 -0
  83. data/spec/link_spec.rb +106 -0
  84. data/spec/note_spec.rb +110 -0
  85. data/spec/organization_spec.rb +151 -0
  86. data/spec/person_spec.rb +132 -0
  87. data/spec/rootmodel_spec.rb +371 -0
  88. data/spec/spec_helper.rb +30 -0
  89. data/spec/templating_spec.rb +12 -0
  90. metadata +306 -0
@@ -0,0 +1,116 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'go_import'
4
+ require 'roo'
5
+ require_relative("../converter")
6
+
7
+ def convert_source
8
+ puts "Trying to convert Excel source to LIME Go..."
9
+
10
+ converter = Converter.new
11
+
12
+ # *** TODO:
13
+ #
14
+ # Modify the name of the sheets. Or add/remove sheets based on
15
+ # your Excel file.
16
+
17
+ # First we read each sheet from the excel file into separate
18
+ # variables
19
+ excel_workbook = GoImport::ExcelHelper.Open(EXCEL_FILE)
20
+
21
+ if defined?(COWORKER_SHEET)
22
+ if excel_workbook.has_sheet?(COWORKER_SHEET)
23
+ coworker_rows = excel_workbook.rows_for_sheet COWORKER_SHEET
24
+ else
25
+ puts "Warning: can't find sheet '#{COWORKER_SHEET}'"
26
+ end
27
+ end
28
+
29
+ if defined?(ORGANIZATION_SHEET)
30
+ if excel_workbook.has_sheet?(ORGANIZATION_SHEET)
31
+ organization_rows = excel_workbook.rows_for_sheet ORGANIZATION_SHEET
32
+ else
33
+ puts "Warning: can't find sheet '#{ORGANIZATION_SHEET}'"
34
+ end
35
+ end
36
+
37
+ if defined?(PERSON_SHEET)
38
+ if excel_workbook.has_sheet?(PERSON_SHEET)
39
+ person_rows = excel_workbook.rows_for_sheet PERSON_SHEET
40
+ else
41
+ puts "Warning: can't find sheet '#{PERSON_SHEET}'"
42
+ end
43
+ end
44
+
45
+ if defined?(DEAL_SHEET)
46
+ if excel_workbook.has_sheet?(DEAL_SHEET)
47
+ deal_rows = excel_workbook.rows_for_sheet DEAL_SHEET
48
+ else
49
+ puts "Warning: can't find sheet '#{DEAL_SHEET}'"
50
+ end
51
+ end
52
+
53
+ if defined?(NOTE_SHEET)
54
+ if excel_workbook.has_sheet?(NOTE_SHEET)
55
+ note_rows = excel_workbook.rows_for_sheet NOTE_SHEET
56
+ else
57
+ puts "Warning: can't find sheet '#{NOTE_SHEET}'"
58
+ end
59
+ end
60
+
61
+ # Then we create a rootmodel that will contain all data that
62
+ # should be exported to LIME Go.
63
+ rootmodel = GoImport::RootModel.new
64
+
65
+ # And configure the model if we have any custom fields
66
+ converter.configure rootmodel
67
+
68
+ # Now start to read data from the excel file and add to the
69
+ # rootmodel. We begin with coworkers since they are referenced
70
+ # from everywhere (orgs, deals, notes)
71
+ if defined?(coworker_rows) && !coworker_rows.nil?
72
+ puts "Trying to convert coworkers..."
73
+ coworker_rows.each do |row|
74
+ rootmodel.add_coworker(converter.to_coworker(row))
75
+ end
76
+ end
77
+
78
+ # Then create organizations, they are only referenced by
79
+ # coworkers.
80
+ if defined?(organization_rows) && !organization_rows.nil?
81
+ puts "Trying to convert organizations..."
82
+ organization_rows.each do |row|
83
+ rootmodel.add_organization(converter.to_organization(row, rootmodel))
84
+ end
85
+ end
86
+
87
+ # Add people and link them to their organizations
88
+ if defined?(person_rows) && !person_rows.nil?
89
+ puts "Trying to convert persons..."
90
+ person_rows.each do |row|
91
+ # People are special since they are not added directly to
92
+ # the root model
93
+ converter.import_person_to_organization(row, rootmodel)
94
+ end
95
+ end
96
+
97
+ # Deals can connected to coworkers, organizations and people.
98
+ if defined?(deal_rows) && !deal_rows.nil?
99
+ puts "Trying to convert deals..."
100
+ deal_rows.each do |row|
101
+ rootmodel.add_deal(converter.to_deal(row, rootmodel))
102
+ end
103
+ end
104
+
105
+ # Notes must be owned by a coworker and the be added to
106
+ # organizations and notes and might refernce a person
107
+ if defined?(note_rows) && !note_rows.nil?
108
+ puts "Trying to convert notes..."
109
+ note_rows.each do |row|
110
+ rootmodel.add_note(converter.to_note(row, rootmodel))
111
+ end
112
+ end
113
+
114
+ return rootmodel
115
+ end
116
+
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'roo'
5
+ gem 'thor'
6
+ #gem 'go_import'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,130 @@
1
+ # encoding: UTF-8
2
+ require 'go_import'
3
+ require 'roo'
4
+
5
+ # This Converter will convert an Excel file to a XML file that can be
6
+ # imported into LIME Go.
7
+ #
8
+ # You need to customize this script to suit your Excel file.
9
+
10
+ # First set the name of the Excel file to convert. It is a filename
11
+ # relative to this folder.
12
+ EXCEL_FILE = "template.xlsx"
13
+
14
+ COWORKER_SHEET = "Medarbetare"
15
+ ORGANIZATION_SHEET = "Företag"
16
+ PERSON_SHEET = "Kontaktperson"
17
+ DEAL_SHEET = "Affär"
18
+ NOTE_SHEET = "Anteckningar"
19
+
20
+ # Then you need to modify the script below according to the TODO
21
+ # comments.
22
+
23
+ # To generate the xml-file that should be sent to LIME Go with the
24
+ # command:
25
+ # go-import run
26
+
27
+ class Converter
28
+ def configure(rootmodel)
29
+ # *** TODO: Add custom field to your rootmodel here. Custom fields
30
+ # can be added to organization, deal and person. Valid types
31
+ # are :String and :Link. If no type is specified :String is
32
+ # used as default.
33
+
34
+ # rootmodel.settings.with_organization do |organization|
35
+ # organization.set_custom_field( { :integrationid => 'source', :title => 'Källa', :type => :Link } )
36
+ # end
37
+ end
38
+
39
+ def import_person_to_organization(row, rootmodel)
40
+ person = to_person(row, rootmodel)
41
+ organization = rootmodel.find_organization_by_integration_id(row['ID'])
42
+
43
+ if !organization.nil?
44
+ organization.add_employee(person)
45
+ end
46
+ end
47
+
48
+ def to_coworker(row)
49
+ coworker = GoImport::Coworker.new()
50
+
51
+ # *** TODO:
52
+ #
53
+ # Set coworker properties from the row.
54
+
55
+ coworker.parse_name_to_firstname_lastname_se row['Namn/Titel']
56
+ coworker.integration_id = row['Namn/Titel']
57
+ if GoImport::EmailHelper.is_valid?(row['Email'])
58
+ coworker.email = row['Email']
59
+ end
60
+
61
+ return coworker
62
+ end
63
+
64
+ def to_deal(row, rootmodel)
65
+ deal = GoImport::Deal.new()
66
+
67
+ # *** TODO:
68
+ #
69
+ # Set deal properties from the row.
70
+
71
+ return deal
72
+ end
73
+
74
+ def to_organization(row, rootmodel)
75
+ organization = GoImport::Organization.new()
76
+ organization.set_tag "Importerad"
77
+
78
+ # Integrationid is typically the id in the system that we are
79
+ # getting the csv from. Must be set to be able to import the
80
+ # same file more than once without creating duplicates
81
+ organization.integration_id = row['ID']
82
+
83
+ # Sets the organization's relation. Relation must be a value
84
+ # from GoImport::Relation.
85
+ organization.relation = GoImport::Relation::IsACustomer
86
+
87
+ # *** TODO:
88
+ #
89
+ # Set organization properties from the row.
90
+
91
+ organization.name = row['Namn']
92
+
93
+ # Custom fields should be set like this.
94
+ # organization.set_custom_value("source", "internet")
95
+
96
+ return organization
97
+ end
98
+
99
+ def to_person(row, rootmodel)
100
+ person = GoImport::Person.new()
101
+
102
+ # *** TODO:
103
+ #
104
+ # Set person properties from the row.
105
+
106
+ person.parse_name_to_firstname_lastname_se(row['Namn'])
107
+ if GoImport::EmailHelper.is_valid?(row['Email'])
108
+ person.email = row['Email']
109
+ end
110
+ person.mobile_phone_number, person.direct_phone_number =
111
+ GoImport::PhoneHelper.parse_numbers(row['Telefon'], [",", "/", "\\"])
112
+
113
+ return person
114
+ end
115
+
116
+ def to_note(row, rootmodel)
117
+ note = GoImport::Note.new()
118
+
119
+ # *** TODO:
120
+ #
121
+ # Set note properties from the row.
122
+
123
+ note.organization = rootmodel.find_organization_by_integration_id(row['ID'])
124
+ note.created_by = rootmodel.find_coworker_by_integration_id(row['Skapad av'])
125
+ note.text = row['Text']
126
+ note.date = row['Skapad den']
127
+
128
+ return note
129
+ end
130
+ end
@@ -0,0 +1,26 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ #require File.expand_path("../../config/environment", __FILE__)
3
+ #require 'rspec/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ # ## Mock Framework
7
+ #
8
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
9
+ #
10
+ # config.mock_with :mocha
11
+ # config.mock_with :flexmock
12
+ # config.mock_with :rr
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = "random"
19
+
20
+ # Allow both should and expect syntax
21
+ # http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = [:should, :expect]
24
+ end
25
+ end
26
+
@@ -0,0 +1,18 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'tomodel'
5
+
6
+ describe 'Model' do
7
+ before(:all) do
8
+ converter = Converter.new
9
+ samplefile = File.join(File.dirname(__FILE__), '..', 'template.xlsx')
10
+ @rootmodel = converter.to_model(samplefile)
11
+ end
12
+
13
+ it "will find something with a name" do
14
+ organization = @rootmodel.organizations[0]
15
+ organization.name.length.should > 0
16
+ end
17
+ end
18
+
Binary file
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'go_import'
3
+
4
+ describe GoImport::Address do
5
+ describe "Parse line with swedish zip and city into zipcode" do
6
+ let (:zip_code) {
7
+ address = GoImport::Address.new
8
+ line = "114 45 STOCKHOLM"
9
+ address.parse_zip_and_address_se(line).zip_code
10
+ }
11
+ it "should have zipcode equal to '114 45'" do
12
+ zip_code.should eq '114 45'
13
+ end
14
+ end
15
+
16
+ describe "Parse line with swedish zip and city into city" do
17
+ let (:city){
18
+ address = GoImport::Address.new
19
+ line = "114 45 STOCKHOLM"
20
+ address.parse_zip_and_address_se(line).city
21
+ }
22
+ it "should have city equal to 'STOCKHOLM'" do
23
+ city.should eq 'STOCKHOLM'
24
+ end
25
+ end
26
+
27
+ describe "Parse line with non-swedish zip and city assuming swedish format" do
28
+ describe "praha example" do
29
+ let (:parse_result){
30
+ address = GoImport::Address.new
31
+ line = "CZ-140 00 PRAHA 4"
32
+ address.parse_zip_and_address_se(line)
33
+ }
34
+ it "should be nil" do
35
+ parse_result.should == nil
36
+ end
37
+ end
38
+ describe "finnish example" do
39
+ let (:parse_result){
40
+ address = GoImport::Address.new
41
+ line = "0511 HELSINKI"
42
+ address.parse_zip_and_address_se(line)
43
+ }
44
+ it "should be nil" do
45
+ parse_result.should == nil
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+ require 'go_import'
3
+
4
+ describe "ClassSettings" do
5
+ let(:class_settings) {
6
+ GoImport::ClassSettings.new
7
+ }
8
+
9
+ it "can set custom field and if there is already an existing custom field, then it is overwritten." do
10
+ class_settings.set_custom_field({:integration_id => "link_to_bi_system", :title => "Link to BI system"})
11
+ class_settings.set_custom_field({:integration_id => "link_to_bi_system", :title => "Link to BI system 2"})
12
+ class_settings.custom_fields.length.should eq 1
13
+ class_settings.custom_fields[0].title.should eq "Link to BI system 2"
14
+ end
15
+
16
+ it "should not allow new custom fields without id and integration id" do
17
+ begin
18
+ class_settings.set_custom_field({:integration_id => "", :id => "", :title => "Link to BI system"})
19
+ rescue
20
+ end
21
+
22
+ class_settings.custom_fields.length.should eq 0
23
+ end
24
+
25
+ it "should allow new custom field with integration_id" do
26
+ class_settings.set_custom_field({:integration_id => "link_to_bi_system", :title => "Link to BI system"})
27
+ class_settings.custom_fields.length.should eq 1
28
+ class_settings.custom_fields[0].title.should eq "Link to BI system"
29
+ end
30
+
31
+ it "should allow new custom field with id" do
32
+ class_settings.set_custom_field({:id => "123", :title => "Link to BI system"})
33
+ class_settings.custom_fields.length.should eq 1
34
+ class_settings.custom_fields[0].title.should eq "Link to BI system"
35
+ end
36
+ end
37
+
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require 'go_import'
4
+
5
+ describe "Coworker" do
6
+ let(:coworker) {
7
+ GoImport::Coworker.new
8
+ }
9
+
10
+ describe "parse_name_to_firstname_lastname_se" do
11
+ it "can parse 'Kalle Nilsson' into firstname 'Kalle' and lastname 'Nilsson'" do
12
+ coworker.parse_name_to_firstname_lastname_se 'Kalle Nilsson'
13
+
14
+ coworker.first_name.should eq 'Kalle'
15
+ coworker.last_name.should eq 'Nilsson'
16
+
17
+ end
18
+
19
+ it "can parse 'Kalle Svensson Nilsson' into firstname 'Kalle' and lastname 'Svensson Nilsson'" do
20
+ coworker.parse_name_to_firstname_lastname_se 'Kalle Svensson Nilsson'
21
+
22
+ coworker.first_name.should eq 'Kalle'
23
+ coworker.last_name.should eq 'Svensson Nilsson'
24
+ end
25
+
26
+ it "sets default name when name is empty" do
27
+ coworker.parse_name_to_firstname_lastname_se '', 'a default'
28
+
29
+ coworker.first_name.should eq 'a default'
30
+ end
31
+
32
+ it "sets default name when name is nil" do
33
+ coworker.parse_name_to_firstname_lastname_se nil, 'a default'
34
+
35
+ coworker.first_name.should eq 'a default'
36
+ end
37
+ end
38
+
39
+ describe "guess_email" do
40
+ it "guesses kalle.nilsson@x.com for coworker with firstname 'Kalle', lastname 'Nilsson' and domain set to 'x.com" do
41
+ coworker.first_name = 'Kalle'
42
+ coworker.last_name = 'Nilsson'
43
+
44
+ guessed = coworker.guess_email 'x.com'
45
+
46
+ guessed.should eq 'kalle.nilsson@x.com'
47
+ end
48
+
49
+ it "guesses '' when lastname is missing" do
50
+ coworker.first_name = 'Kalle'
51
+ coworker.last_name = ''
52
+
53
+ guessed = coworker.guess_email 'x.com'
54
+
55
+ guessed.should eq ''
56
+ end
57
+
58
+ it "guesses '' when firstname is missing" do
59
+ coworker.first_name = nil
60
+ coworker.last_name = 'Nilsson'
61
+
62
+ guessed = coworker.guess_email 'x.com'
63
+
64
+ guessed.should eq ''
65
+ end
66
+
67
+ it "guesses åäöèé to be aaoee" do
68
+ coworker.first_name = 'åäöèé'
69
+ coworker.last_name = 'Nilsson'
70
+
71
+ guessed = coworker.guess_email 'x.com'
72
+
73
+ guessed.should eq 'aaoee.nilsson@x.com'
74
+ end
75
+
76
+ it "guesses 'sven-erik.nilsson@x.com' when firstname has two names with ' ' between them" do
77
+ coworker.first_name = 'Sven Erik'
78
+ coworker.last_name = 'Nilsson'
79
+
80
+ guessed = coworker.guess_email 'x.com'
81
+
82
+ guessed.should eq 'sven-erik.nilsson@x.com'
83
+ end
84
+
85
+ it "guesses 'sven.nilsson-svensson@x.com' when lastnames has two names with ' ' between them" do
86
+ coworker.first_name = 'Sven'
87
+ coworker.last_name = 'Nilsson Svensson'
88
+
89
+ guessed = coworker.guess_email 'x.com'
90
+
91
+ guessed.should eq 'sven.nilsson-svensson@x.com'
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+ require 'go_import'
3
+
4
+ describe "CustomField" do
5
+ before (:all) do
6
+ @custom_field = GoImport::CustomField.new({:id => 'the id',
7
+ :integration_id=>'the key',
8
+ :value=> 'the value'})
9
+ end
10
+
11
+ it "is the same as a custom field with the same integration_id" do
12
+ @custom_field.same_as?(GoImport::CustomField.new({:integration_id=>'the key',
13
+ :value=> 'the value 2'})).should eq true
14
+ end
15
+
16
+ it "is the same as a custom field with the same id" do
17
+ @custom_field.same_as?(GoImport::CustomField.new({:id=>'the id',
18
+ :value=> 'the value 2'})).should eq true
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,104 @@
1
+ require "spec_helper"
2
+ require "go_import"
3
+
4
+ describe "DealClassSettings" do
5
+ let(:deal_class_settings) {
6
+ GoImport::DealClassSettings.new
7
+ }
8
+
9
+ it "should not allow new deal status without a label" do
10
+ # given, when
11
+ begin
12
+ deal_class_settings.add_status({:integration_id => "123"})
13
+ rescue GoImport::InvalidDealStatusError
14
+ end
15
+
16
+ # then
17
+ deal_class_settings.statuses.length.should eq 0
18
+ end
19
+
20
+ it "should set assessment to NotAnEndState as default" do
21
+ # given, when
22
+ status = deal_class_settings.add_status({:label => "1. Kvalificering"})
23
+
24
+ # then
25
+ status.assessment.should eq GoImport::DealState::NotAnEndState
26
+ end
27
+
28
+ it "should set assessment if specified" do
29
+ # given, when
30
+ status = deal_class_settings.add_status({
31
+ :label => "4. Won deal",
32
+ :assessment => GoImport::DealState::PositiveEndState
33
+ })
34
+
35
+ # then
36
+ status.assessment.should eq GoImport::DealState::PositiveEndState
37
+ end
38
+
39
+ it "should find a status by case insensitive label" do
40
+ # given
41
+ deal_class_settings.add_status({:label => "1. Kvalificering"})
42
+ deal_class_settings.add_status({:label => "2. Skickat offert"})
43
+
44
+ # when
45
+ status = deal_class_settings.find_status_by_label("2. skICkat OfFert")
46
+
47
+ # then
48
+ status.label.should eq "2. Skickat offert"
49
+ end
50
+
51
+ it "should find a status by integration id" do
52
+ # given
53
+ deal_class_settings.add_status({:label => "1. Kvalificering", :integration_id => "qualify"})
54
+ deal_class_settings.add_status({:label => "2. Skickat offert", :integration_id => "tender sent"})
55
+
56
+ # when
57
+ status = deal_class_settings.find_status_by_integration_id("tender SeNT")
58
+
59
+ # then
60
+ status.label.should eq "2. Skickat offert"
61
+ end
62
+
63
+ it "should find nil by label if no statuses are defined" do
64
+ # given, when
65
+ status = deal_class_settings.find_status_by_label("3. Won")
66
+
67
+ # then
68
+ status.should eq nil
69
+ end
70
+
71
+ it "should find nil by label if label is nil" do
72
+ # given
73
+ deal_class_settings.add_status({:label => "1. Kvalificering", :integration_id => "qualify"})
74
+ deal_class_settings.add_status({:label => "2. Skickat offert", :integration_id => "tender sent"})
75
+
76
+ # when
77
+ status = deal_class_settings.find_status_by_label(nil)
78
+
79
+ # then
80
+ status.should eq nil
81
+ end
82
+
83
+ it "should find nil by integration id if no statuses are defined" do
84
+ # given, when
85
+ status = deal_class_settings.find_status_by_integration_id("3. Won")
86
+
87
+ # then
88
+ status.should eq nil
89
+ end
90
+
91
+ it "should find nil by integration id if integration id is nil" do
92
+ # given
93
+ deal_class_settings.add_status({:label => "1. Kvalificering", :integration_id => "qualify"})
94
+ deal_class_settings.add_status({:label => "2. Skickat offert", :integration_id => "tender sent"})
95
+
96
+ # when
97
+ status = deal_class_settings.find_status_by_integration_id(nil)
98
+
99
+ # then
100
+ status.should eq nil
101
+ end
102
+ end
103
+
104
+