nexus_mods 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,135 @@
1
+ module NexusModsTest
2
+
3
+ module Factories
4
+
5
+ module Games
6
+
7
+ # Test game with id 100
8
+ def json_game100
9
+ {
10
+ 'id' => 100,
11
+ 'name' => 'Morrowind',
12
+ 'forum_url' => 'https://forums.nexusmods.com/index.php?/forum/111-morrowind/',
13
+ 'nexusmods_url' => 'http://www.nexusmods.com/morrowind',
14
+ 'genre' => 'RPG',
15
+ 'file_count' => 14_143,
16
+ 'downloads' => 20_414_985,
17
+ 'domain_name' => 'morrowind',
18
+ 'approved_date' => 1,
19
+ 'file_views' => 100_014_750,
20
+ 'authors' => 2062,
21
+ 'file_endorsements' => 719_262,
22
+ 'mods' => 6080,
23
+ 'categories' => [
24
+ {
25
+ 'category_id' => 1,
26
+ 'name' => 'Morrowind',
27
+ 'parent_category' => false
28
+ },
29
+ {
30
+ 'category_id' => 2,
31
+ 'name' => 'Buildings',
32
+ 'parent_category' => 1
33
+ }
34
+ ]
35
+ }
36
+ end
37
+
38
+ # Test game with id 101
39
+ def json_game101
40
+ {
41
+ 'id' => 101,
42
+ 'name' => 'Oblivion',
43
+ 'forum_url' => 'https://forums.nexusmods.com/index.php?/forum/131-oblivion/',
44
+ 'nexusmods_url' => 'http://www.nexusmods.com/oblivion',
45
+ 'genre' => 'RPG',
46
+ 'file_count' => 52_775,
47
+ 'downloads' => 187_758_634,
48
+ 'domain_name' => 'oblivion',
49
+ 'approved_date' => 1,
50
+ 'file_views' => 880_508_188,
51
+ 'authors' => 10_673,
52
+ 'file_endorsements' => 4_104_067,
53
+ 'mods' => 29_220,
54
+ 'categories' => [
55
+ {
56
+ 'category_id' => 20,
57
+ 'name' => 'Oblivion',
58
+ 'parent_category' => false
59
+ },
60
+ {
61
+ 'category_id' => 22,
62
+ 'name' => 'New structures - Buildings',
63
+ 'parent_category' => 20
64
+ }
65
+ ]
66
+ }
67
+ end
68
+
69
+ # Expect a game to be the test game of id 100
70
+ #
71
+ # Parameters::
72
+ # * *game* (NexusMods::Api::Game): Game to validate
73
+ def expect_game_to_be_game100(game)
74
+ expect(game.id).to eq 100
75
+ expect(game.name).to eq 'Morrowind'
76
+ expect(game.forum_url).to eq 'https://forums.nexusmods.com/index.php?/forum/111-morrowind/'
77
+ expect(game.nexusmods_url).to eq 'http://www.nexusmods.com/morrowind'
78
+ expect(game.genre).to eq 'RPG'
79
+ expect(game.files_count).to eq 14_143
80
+ expect(game.downloads_count).to eq 20_414_985
81
+ expect(game.domain_name).to eq 'morrowind'
82
+ expect(game.approved_date).to eq Time.parse('1970-01-01 00:00:01 +0000')
83
+ expect(game.files_views).to eq 100_014_750
84
+ expect(game.authors_count).to eq 2062
85
+ expect(game.files_endorsements).to eq 719_262
86
+ expect(game.mods_count).to eq 6080
87
+ game_categories = game.categories
88
+ expect(game_categories.size).to eq 2
89
+ expect(game_categories.first.id).to eq 1
90
+ expect(game_categories.first.name).to eq 'Morrowind'
91
+ expect(game_categories.first.parent_category).to be_nil
92
+ expect(game_categories[1].id).to eq 2
93
+ expect(game_categories[1].name).to eq 'Buildings'
94
+ expect(game_categories[1].parent_category).not_to be_nil
95
+ expect(game_categories[1].parent_category.id).to eq 1
96
+ expect(game_categories[1].parent_category.name).to eq 'Morrowind'
97
+ expect(game_categories[1].parent_category.parent_category).to be_nil
98
+ end
99
+
100
+ # Expect a game to be the test game of id 101
101
+ #
102
+ # Parameters::
103
+ # * *game* (NexusMods::Api::Game): Game to validate
104
+ def expect_game_to_be_game101(game)
105
+ expect(game.id).to eq 101
106
+ expect(game.name).to eq 'Oblivion'
107
+ expect(game.forum_url).to eq 'https://forums.nexusmods.com/index.php?/forum/131-oblivion/'
108
+ expect(game.nexusmods_url).to eq 'http://www.nexusmods.com/oblivion'
109
+ expect(game.genre).to eq 'RPG'
110
+ expect(game.files_count).to eq 52_775
111
+ expect(game.downloads_count).to eq 187_758_634
112
+ expect(game.domain_name).to eq 'oblivion'
113
+ expect(game.approved_date).to eq Time.parse('1970-01-01 00:00:01 +0000')
114
+ expect(game.files_views).to eq 880_508_188
115
+ expect(game.authors_count).to eq 10_673
116
+ expect(game.files_endorsements).to eq 4_104_067
117
+ expect(game.mods_count).to eq 29_220
118
+ game_categories = game.categories
119
+ expect(game_categories.size).to eq 2
120
+ expect(game_categories.first.id).to eq 20
121
+ expect(game_categories.first.name).to eq 'Oblivion'
122
+ expect(game_categories.first.parent_category).to be_nil
123
+ expect(game_categories[1].id).to eq 22
124
+ expect(game_categories[1].name).to eq 'New structures - Buildings'
125
+ expect(game_categories[1].parent_category).not_to be_nil
126
+ expect(game_categories[1].parent_category.id).to eq 20
127
+ expect(game_categories[1].parent_category.name).to eq 'Oblivion'
128
+ expect(game_categories[1].parent_category.parent_category).to be_nil
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ end
@@ -0,0 +1,113 @@
1
+ module NexusModsTest
2
+
3
+ module Factories
4
+
5
+ module ModFiles
6
+
7
+ # Test mod file with id 2472
8
+ def json_mod_file2472
9
+ {
10
+ 'id' => [
11
+ 2472,
12
+ 1704
13
+ ],
14
+ 'uid' => 7_318_624_274_856,
15
+ 'file_id' => 2472,
16
+ 'name' => 'ApachiiSkyHair_v_1_6_Full',
17
+ 'version' => '1.6.Full',
18
+ 'category_id' => 4,
19
+ 'category_name' => 'OLD_VERSION',
20
+ 'is_primary' => false,
21
+ 'file_name' => 'ApachiiSkyHair_v_1_6_Full-2014-1-6-Full.7z',
22
+ 'uploaded_timestamp' => 1_477_967_645,
23
+ 'uploaded_time' => '2016-11-01T02:34:05.000+00:00',
24
+ 'mod_version' => '1.6.Full',
25
+ 'external_virus_scan_url' => 'https://www.virustotal.com/file/3dcc96dce0b846ea643d626c48bd6ad08752da8232f3d29be644d36e1fd627cf/analysis/1477978674/',
26
+ 'description' => '[b][color=orange] NOT optimized meshes. Standalone. Adds 42 new hairstyles for females, 21 hair for males and 5 hairs for Female Khajiit- 2 hairs for Male Khajiit[/color][/b] ',
27
+ 'size' => 304_347,
28
+ 'size_kb' => 304_347,
29
+ 'size_in_bytes' => 309_251_227,
30
+ 'changelog_html' => nil,
31
+ 'content_preview_link' => 'https://file-metadata.nexusmods.com/file/nexus-files-meta/1704/2014/ApachiiSkyHair_v_1_6_Full-2014-1-6-Full.7z.json'
32
+ }
33
+ end
34
+
35
+ # Test mod file with id 2487
36
+ def json_mod_file2487
37
+ {
38
+ 'id' => [
39
+ 2487,
40
+ 1705
41
+ ],
42
+ 'uid' => 7_318_624_274_857,
43
+ 'file_id' => 2487,
44
+ 'name' => 'ApachiiSkyHairMale_v_1_2',
45
+ 'version' => '1.2',
46
+ 'category_id' => 4,
47
+ 'category_name' => 'OLD_VERSION',
48
+ 'is_primary' => false,
49
+ 'file_name' => 'ApachiiSkyHairMale_v_1_2-2014-1-2.7z',
50
+ 'uploaded_timestamp' => 1_477_968_373,
51
+ 'uploaded_time' => '2016-11-01T02:46:13.000+00:00',
52
+ 'mod_version' => '1.2',
53
+ 'external_virus_scan_url' => 'https://www.virustotal.com/file/3e86106233499ac43383c32ce4a2d8e162dc6e940b4d228f649a701b71ee5676/analysis/1477979366/',
54
+ 'description' => 'NOT optimezed meshes. Standalone 55 Male hairs - Not included in ApachiiSkyHair v_1_6_Full ',
55
+ 'size' => 204_347,
56
+ 'size_kb' => 204_347,
57
+ 'size_in_bytes' => 209_251_227,
58
+ 'changelog_html' => nil,
59
+ 'content_preview_link' => 'https://file-metadata.nexusmods.com/file/nexus-files-meta/1704/2014/ApachiiSkyHairMale_v_1_2-2014-1-2.7z.json'
60
+ }
61
+ end
62
+
63
+ # Expect a mod's file to be the example one with id 2472
64
+ #
65
+ # Parameters::
66
+ # * *mod_file* (NexusMods::Api::File): Mod file to validate
67
+ def expect_mod_file_to_be2472(mod_file)
68
+ expect(mod_file.ids).to eq [2472, 1704]
69
+ expect(mod_file.uid).to eq 7_318_624_274_856
70
+ expect(mod_file.id).to eq 2472
71
+ expect(mod_file.name).to eq 'ApachiiSkyHair_v_1_6_Full'
72
+ expect(mod_file.version).to eq '1.6.Full'
73
+ expect(mod_file.category_id).to eq :old
74
+ expect(mod_file.category_name).to eq 'OLD_VERSION'
75
+ expect(mod_file.is_primary).to be false
76
+ expect(mod_file.size).to eq 309_251_227
77
+ expect(mod_file.file_name).to eq 'ApachiiSkyHair_v_1_6_Full-2014-1-6-Full.7z'
78
+ expect(mod_file.uploaded_time).to eq Time.parse('2016-11-01T02:34:05.000+00:00')
79
+ expect(mod_file.mod_version).to eq '1.6.Full'
80
+ expect(mod_file.external_virus_scan_url).to eq 'https://www.virustotal.com/file/3dcc96dce0b846ea643d626c48bd6ad08752da8232f3d29be644d36e1fd627cf/analysis/1477978674/'
81
+ expect(mod_file.description).to eq '[b][color=orange] NOT optimized meshes. Standalone. Adds 42 new hairstyles for females, 21 hair for males and 5 hairs for Female Khajiit- 2 hairs for Male Khajiit[/color][/b] '
82
+ expect(mod_file.changelog_html).to be_nil
83
+ expect(mod_file.content_preview_url).to eq 'https://file-metadata.nexusmods.com/file/nexus-files-meta/1704/2014/ApachiiSkyHair_v_1_6_Full-2014-1-6-Full.7z.json'
84
+ end
85
+
86
+ # Expect a mod's file to be the example one with id 2487
87
+ #
88
+ # Parameters::
89
+ # * *mod_file* (NexusMods::Api::File): Mod file to validate
90
+ def expect_mod_file_to_be2487(mod_file)
91
+ expect(mod_file.ids).to eq [2487, 1705]
92
+ expect(mod_file.uid).to eq 7_318_624_274_857
93
+ expect(mod_file.id).to eq 2487
94
+ expect(mod_file.name).to eq 'ApachiiSkyHairMale_v_1_2'
95
+ expect(mod_file.version).to eq '1.2'
96
+ expect(mod_file.category_id).to eq :old
97
+ expect(mod_file.category_name).to eq 'OLD_VERSION'
98
+ expect(mod_file.is_primary).to be false
99
+ expect(mod_file.size).to eq 209_251_227
100
+ expect(mod_file.file_name).to eq 'ApachiiSkyHairMale_v_1_2-2014-1-2.7z'
101
+ expect(mod_file.uploaded_time).to eq Time.parse('2016-11-01T02:46:13.000+00:00')
102
+ expect(mod_file.mod_version).to eq '1.2'
103
+ expect(mod_file.external_virus_scan_url).to eq 'https://www.virustotal.com/file/3e86106233499ac43383c32ce4a2d8e162dc6e940b4d228f649a701b71ee5676/analysis/1477979366/'
104
+ expect(mod_file.description).to eq 'NOT optimezed meshes. Standalone 55 Male hairs - Not included in ApachiiSkyHair v_1_6_Full '
105
+ expect(mod_file.changelog_html).to be_nil
106
+ expect(mod_file.content_preview_url).to eq 'https://file-metadata.nexusmods.com/file/nexus-files-meta/1704/2014/ApachiiSkyHairMale_v_1_2-2014-1-2.7z.json'
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,144 @@
1
+ module NexusModsTest
2
+
3
+ module Factories
4
+
5
+ module Mods
6
+
7
+ # Example of JSON object returned by the API for a mod information, having all possible fields
8
+ def json_complete_mod
9
+ {
10
+ 'name' => 'ApachiiSkyHair SSE',
11
+ 'summary' => 'New Female and Male Hairstyles for Humans, Elves and Orcs. Converted hair from Sims2 and Sims3.<br />Standalone version.',
12
+ 'description' => 'Mod description',
13
+ 'picture_url' => 'https://staticdelivery.nexusmods.com/mods/1704/images/10168-1-1392817986.jpg',
14
+ 'mod_downloads' => 13_634_545,
15
+ 'mod_unique_downloads' => 4_052_221,
16
+ 'uid' => 7_318_624_272_650,
17
+ 'mod_id' => 2014,
18
+ 'game_id' => 1704,
19
+ 'allow_rating' => true,
20
+ 'domain_name' => 'skyrimspecialedition',
21
+ 'category_id' => 26,
22
+ 'version' => '1.6.Full',
23
+ 'endorsement_count' => 298_845,
24
+ 'created_timestamp' => 1_477_972_056,
25
+ 'created_time' => '2016-11-01T03:47:36.000+00:00',
26
+ 'updated_timestamp' => 1_507_398_546,
27
+ 'updated_time' => '2017-10-07T17:49:06.000+00:00',
28
+ 'author' => 'Apachii',
29
+ 'uploaded_by' => 'apachii',
30
+ 'uploaded_users_profile_url' => 'http://www.nexusmods.com/games/users/283148',
31
+ 'contains_adult_content' => false,
32
+ 'status' => 'published',
33
+ 'available' => true,
34
+ 'user' => {
35
+ 'member_id' => 283_148,
36
+ 'member_group_id' => 27,
37
+ 'name' => 'apachii'
38
+ },
39
+ 'endorsement' => {
40
+ 'endorse_status' => 'Undecided',
41
+ 'timestamp' => nil,
42
+ 'version' => nil
43
+ }
44
+ }
45
+ end
46
+
47
+ # Example of JSON object returned by the API for a mod information, having minimum fields
48
+ def json_partial_mod
49
+ {
50
+ 'mod_downloads' => 13_634_545,
51
+ 'mod_unique_downloads' => 4_052_221,
52
+ 'uid' => 7_318_624_272_650,
53
+ 'mod_id' => 2014,
54
+ 'game_id' => 1704,
55
+ 'allow_rating' => true,
56
+ 'domain_name' => 'skyrimspecialedition',
57
+ 'category_id' => 26,
58
+ 'version' => '1.6.Full',
59
+ 'endorsement_count' => 298_845,
60
+ 'created_timestamp' => 1_477_972_056,
61
+ 'created_time' => '2016-11-01T03:47:36.000+00:00',
62
+ 'updated_timestamp' => 1_507_398_546,
63
+ 'updated_time' => '2017-10-07T17:49:06.000+00:00',
64
+ 'author' => 'Apachii',
65
+ 'uploaded_by' => 'apachii',
66
+ 'uploaded_users_profile_url' => 'http://www.nexusmods.com/games/users/283148',
67
+ 'contains_adult_content' => false,
68
+ 'status' => 'published',
69
+ 'available' => true,
70
+ 'user' => {
71
+ 'member_id' => 283_148,
72
+ 'member_group_id' => 27,
73
+ 'name' => 'apachii'
74
+ }
75
+ }
76
+ end
77
+
78
+ # Expect a mod to be the example complete one
79
+ #
80
+ # Parameters::
81
+ # * *mod* (NexusMods::Api::Mod): Mod to validate
82
+ def expect_mod_to_be_complete(mod)
83
+ expect(mod.name).to eq 'ApachiiSkyHair SSE'
84
+ expect(mod.summary).to eq 'New Female and Male Hairstyles for Humans, Elves and Orcs. Converted hair from Sims2 and Sims3.<br />Standalone version.'
85
+ expect(mod.description).to eq 'Mod description'
86
+ expect(mod.picture_url).to eq 'https://staticdelivery.nexusmods.com/mods/1704/images/10168-1-1392817986.jpg'
87
+ expect(mod.downloads_count).to eq 13_634_545
88
+ expect(mod.unique_downloads_count).to eq 4_052_221
89
+ expect(mod.uid).to eq 7_318_624_272_650
90
+ expect(mod.mod_id).to eq 2014
91
+ expect(mod.game_id).to eq 1704
92
+ expect(mod.allow_rating).to be true
93
+ expect(mod.domain_name).to eq 'skyrimspecialedition'
94
+ expect(mod.category_id).to eq 26
95
+ expect(mod.version).to eq '1.6.Full'
96
+ expect(mod.endorsements_count).to eq 298_845
97
+ expect(mod.created_time).to eq Time.parse('2016-11-01T03:47:36.000+00:00')
98
+ expect(mod.updated_time).to eq Time.parse('2017-10-07T17:49:06.000+00:00')
99
+ expect(mod.author).to eq 'Apachii'
100
+ expect(mod.contains_adult_content).to be false
101
+ expect(mod.status).to eq 'published'
102
+ expect(mod.available).to be true
103
+ expect(mod.uploader.member_id).to eq 283_148
104
+ expect(mod.uploader.member_group_id).to eq 27
105
+ expect(mod.uploader.name).to eq 'apachii'
106
+ expect(mod.uploader.profile_url).to eq 'http://www.nexusmods.com/games/users/283148'
107
+ end
108
+
109
+ # Expect a mod to be the example partial one
110
+ #
111
+ # Parameters::
112
+ # * *mod* (NexusMods::Api::Mod): Mod to validate
113
+ def expect_mod_to_be_partial(mod)
114
+ expect(mod.name).to be_nil
115
+ expect(mod.summary).to be_nil
116
+ expect(mod.description).to be_nil
117
+ expect(mod.picture_url).to be_nil
118
+ expect(mod.downloads_count).to eq 13_634_545
119
+ expect(mod.unique_downloads_count).to eq 4_052_221
120
+ expect(mod.uid).to eq 7_318_624_272_650
121
+ expect(mod.mod_id).to eq 2014
122
+ expect(mod.game_id).to eq 1704
123
+ expect(mod.allow_rating).to be true
124
+ expect(mod.domain_name).to eq 'skyrimspecialedition'
125
+ expect(mod.category_id).to eq 26
126
+ expect(mod.version).to eq '1.6.Full'
127
+ expect(mod.endorsements_count).to eq 298_845
128
+ expect(mod.created_time).to eq Time.parse('2016-11-01T03:47:36.000+00:00')
129
+ expect(mod.updated_time).to eq Time.parse('2017-10-07T17:49:06.000+00:00')
130
+ expect(mod.author).to eq 'Apachii'
131
+ expect(mod.contains_adult_content).to be false
132
+ expect(mod.status).to eq 'published'
133
+ expect(mod.available).to be true
134
+ expect(mod.uploader.member_id).to eq 283_148
135
+ expect(mod.uploader.member_group_id).to eq 27
136
+ expect(mod.uploader.name).to eq 'apachii'
137
+ expect(mod.uploader.profile_url).to eq 'http://www.nexusmods.com/games/users/283148'
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+ end
@@ -1,9 +1,12 @@
1
1
  require 'digest'
2
2
  require 'webmock/rspec'
3
3
  require 'rspec/support/object_formatter'
4
+ require 'nexus_mods_test/factories/games'
5
+ require 'nexus_mods_test/factories/mods'
6
+ require 'nexus_mods_test/factories/mod_files'
4
7
  require 'nexus_mods'
5
8
 
6
- module NexusModsTests
9
+ module NexusModsTest
7
10
 
8
11
  module Helpers
9
12
 
@@ -72,6 +75,7 @@ module NexusModsTests
72
75
  # * *message* (String): Mocked returned message [default: 'OK']
73
76
  # * *json* (Object): Mocked JSON body [default: {}]
74
77
  # * *headers* (Hash<String,String>): Mocked additional HTTP headers [default: {}]
78
+ # * *times* (Integer): Number of times the call is expected [default: 1]
75
79
  def expect_http_call_to(
76
80
  host: 'api.nexusmods.com',
77
81
  http_method: :get,
@@ -80,7 +84,8 @@ module NexusModsTests
80
84
  code: 200,
81
85
  message: 'OK',
82
86
  json: {},
83
- headers: {}
87
+ headers: {},
88
+ times: 1
84
89
  )
85
90
  json_as_str = json.to_json
86
91
  mocked_etag = "W/\"#{Digest::MD5.hexdigest("#{path}|#{json_as_str}")}\""
@@ -93,19 +98,25 @@ module NexusModsTests
93
98
  else
94
99
  @expected_returned_etags << mocked_etag
95
100
  end
96
- stub_request(http_method, "https://#{host}#{path}").with(headers: expected_request_headers).to_return(
97
- status: [code, message],
98
- body: json_as_str,
99
- headers: DEFAULT_API_HEADERS.
100
- merge(
101
- 'etag' => mocked_etag
102
- ).
103
- merge(headers)
104
- )
101
+ @expected_stubs << [
102
+ stub_request(http_method, "https://#{host}#{path}").with(headers: expected_request_headers).to_return(
103
+ status: [code, message],
104
+ body: json_as_str,
105
+ headers: DEFAULT_API_HEADERS.
106
+ merge(
107
+ 'etag' => mocked_etag
108
+ ).
109
+ merge(headers)
110
+ ),
111
+ times
112
+ ]
105
113
  end
106
114
 
107
115
  # Expect a successfull call made to validate the user
108
- def expect_validate_user
116
+ #
117
+ # Parameters::
118
+ # * *times* (Integer): Number of times the call is expected [default: 1]
119
+ def expect_validate_user(times: 1)
109
120
  expect_http_call_to(
110
121
  path: '/v1/users/validate.json',
111
122
  json: {
@@ -118,7 +129,8 @@ module NexusModsTests
118
129
  profile_url: 'https://www.nexusmods.com/Contents/Images/noavatar.gif',
119
130
  is_supporter: false,
120
131
  is_premium: false
121
- }
132
+ },
133
+ times:
122
134
  )
123
135
  end
124
136
 
@@ -127,12 +139,18 @@ module NexusModsTests
127
139
  end
128
140
 
129
141
  RSpec.configure do |config|
130
- config.include NexusModsTests::Helpers
142
+ config.include NexusModsTest::Helpers
143
+ config.include NexusModsTest::Factories::Games
144
+ config.include NexusModsTest::Factories::Mods
145
+ config.include NexusModsTest::Factories::ModFiles
131
146
  config.before do
132
147
  @nexus_mods = nil
133
148
  # Keep a list of the etags we should have returned, so that we know when queries should contain them
134
149
  # Array<String>
135
150
  @expected_returned_etags = []
151
+ # List of expected stubs and the number of times they were supposed to mock
152
+ # Array< [ WebMock::RequestStub, Integer ] >
153
+ @expected_stubs = []
136
154
  end
137
155
  end
138
156
 
@@ -1,10 +1,9 @@
1
- describe NexusMods::ApiLimits do
1
+ describe NexusMods::Api::ApiLimits do
2
2
 
3
3
  context 'when testing API limits' do
4
4
 
5
5
  it 'gets api limits' do
6
- expect_validate_user
7
- expect_validate_user
6
+ expect_validate_user(times: 2)
8
7
  api_limits = nexus_mods.api_limits
9
8
  expect(api_limits.daily_limit).to eq 2500
10
9
  expect(api_limits.daily_remaining).to eq 2500
@@ -14,6 +13,14 @@ describe NexusMods::ApiLimits do
14
13
  expect(api_limits.hourly_reset).to eq Time.parse('2019-10-02T16:00:00+00:00')
15
14
  end
16
15
 
16
+ it 'compares objects for equality' do
17
+ expect_validate_user(times: 3)
18
+ api_limits1 = nexus_mods.api_limits
19
+ api_limits2 = nexus_mods.api_limits
20
+ expect(api_limits1.object_id).not_to eq api_limits2.object_id
21
+ expect(api_limits1).to eq api_limits2
22
+ end
23
+
17
24
  end
18
25
 
19
26
  end
@@ -0,0 +1,93 @@
1
+ describe NexusMods::Api::Game do
2
+
3
+ context 'when testing games' do
4
+
5
+ before do
6
+ expect_validate_user
7
+ end
8
+
9
+ it 'returns the games list' do
10
+ expect_http_call_to(
11
+ path: '/v1/games.json',
12
+ json: [
13
+ json_game100,
14
+ json_game101
15
+ ]
16
+ )
17
+ games = nexus_mods.games.sort_by(&:id)
18
+ expect(games.size).to eq 2
19
+ expect_game_to_be_game100(games.first)
20
+ expect_game_to_be_game101(games[1])
21
+ end
22
+
23
+ it 'returns a game having missing parent category' do
24
+ expect_http_call_to(
25
+ path: '/v1/games.json',
26
+ json: [
27
+ {
28
+ 'id' => 100,
29
+ 'name' => 'Morrowind',
30
+ 'forum_url' => 'https://forums.nexusmods.com/index.php?/forum/111-morrowind/',
31
+ 'nexusmods_url' => 'http://www.nexusmods.com/morrowind',
32
+ 'genre' => 'RPG',
33
+ 'file_count' => 14_143,
34
+ 'downloads' => 20_414_985,
35
+ 'domain_name' => 'morrowind',
36
+ 'approved_date' => 1,
37
+ 'file_views' => 100_014_750,
38
+ 'authors' => 2062,
39
+ 'file_endorsements' => 719_262,
40
+ 'mods' => 6080,
41
+ 'categories' => [
42
+ {
43
+ 'category_id' => 1,
44
+ 'name' => 'Morrowind',
45
+ 'parent_category' => false
46
+ },
47
+ {
48
+ 'category_id' => 2,
49
+ 'name' => 'Buildings',
50
+ 'parent_category' => 3
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ )
56
+ game = nexus_mods.games.first
57
+ expect(game.id).to eq 100
58
+ expect(game.name).to eq 'Morrowind'
59
+ expect(game.forum_url).to eq 'https://forums.nexusmods.com/index.php?/forum/111-morrowind/'
60
+ expect(game.nexusmods_url).to eq 'http://www.nexusmods.com/morrowind'
61
+ expect(game.genre).to eq 'RPG'
62
+ expect(game.files_count).to eq 14_143
63
+ expect(game.downloads_count).to eq 20_414_985
64
+ expect(game.domain_name).to eq 'morrowind'
65
+ expect(game.approved_date).to eq Time.parse('1970-01-01 00:00:01 +0000')
66
+ expect(game.files_views).to eq 100_014_750
67
+ expect(game.authors_count).to eq 2062
68
+ expect(game.files_endorsements).to eq 719_262
69
+ expect(game.mods_count).to eq 6080
70
+ game_categories = game.categories
71
+ expect(game_categories.size).to eq 2
72
+ expect(game_categories.first.id).to eq 1
73
+ expect(game_categories.first.name).to eq 'Morrowind'
74
+ expect(game_categories.first.parent_category).to be_nil
75
+ expect(game_categories[1].id).to eq 2
76
+ expect(game_categories[1].name).to eq 'Buildings'
77
+ expect(game_categories[1].parent_category).to be_nil
78
+ end
79
+
80
+ it 'compares objects for equality' do
81
+ expect_http_call_to(
82
+ path: '/v1/games.json',
83
+ json: [json_game100]
84
+ )
85
+ game1 = nexus_mods.games.first
86
+ game2 = nexus_mods.games.first
87
+ expect(game1.object_id).not_to eq game2.object_id
88
+ expect(game1).to eq game2
89
+ end
90
+
91
+ end
92
+
93
+ end