forked from ecosyste-ms/packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversions_controller_test.rb
More file actions
215 lines (174 loc) · 8.97 KB
/
Copy pathversions_controller_test.rb
File metadata and controls
215 lines (174 loc) · 8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
require 'test_helper'
class ApiV1VersionsControllerTest < ActionDispatch::IntegrationTest
setup do
@registry = Registry.create(name: 'crates.io', url: 'https://crates.io', ecosystem: 'cargo')
@package = @registry.packages.create(ecosystem: 'cargo', name: 'rand')
@version = @package.versions.create(number: '1.0.0', metadata: {foo: 'bar'}, registry_id: @registry.id)
@omnibor_version = @package.versions.create(number: '2.0.0', integrity: 'sha256-2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824', metadata: { length: 5 }, registry_id: @registry.id)
@pypi_registry = Registry.create(name: 'pypi.org', url: 'https://pypi.org', ecosystem: 'pypi')
@pypi_package = @pypi_registry.packages.create(
ecosystem: 'pypi',
name: 'tomli-w',
metadata: { 'normalized_name' => 'tomli-w' }
)
@pypi_version = @pypi_package.versions.create(number: '1.0.0', registry_id: @pypi_registry.id)
end
test 'list versions for a package' do
get api_v1_registry_package_versions_path(registry_id: @registry.name, package_id: @package.name)
assert_response :success
assert_template 'versions/index', file: 'packages/versions.json.jbuilder'
actual_response = Oj.load(@response.body)
assert_equal actual_response.length, 2
end
test 'filter versions by OmniBOR artifact ID' do
artifact_id = 'gitoid:blob:sha256:2c0eb59d2f7fb34d4326d83952c8425731a200dde6b6f93c465c6e315a4cbd33'
get api_v1_registry_package_versions_path(registry_id: @registry.name, package_id: @package.name, omnibor_artifact_id: artifact_id)
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal 1, actual_response.length
assert_equal '2.0.0', actual_response.first['number']
assert_equal artifact_id, actual_response.first['omnibor_artifact_id']
end
test 'get version of a package' do
get api_v1_registry_package_version_path(registry_id: @registry.name, package_id: @package.name, id: '1.0.0')
assert_response :success
assert_template 'versions/show', file: 'versions/show.json.jbuilder'
actual_response = Oj.load(@response.body)
assert_equal actual_response['number'], "1.0.0"
assert_equal actual_response['metadata'], {"foo"=>"bar"}
end
test 'get recent versions' do
get versions_api_v1_registry_path(id: @registry.name)
assert_response :success
assert_template 'versions/recent', file: 'versions/recent.json.jbuilder'
actual_response = Oj.load(@response.body)
first_version = actual_response.first
assert_equal first_version['package_url'], api_v1_registry_package_url(registry_id: @registry.name, id: @package.name)
assert_equal first_version['number'], "1.0.0"
assert_equal first_version['metadata'], {"foo"=>"bar"}
end
test 'get recent versions excludes versions with invalid package_id' do
dangling_version = @registry.versions.new(number: '2.0.0', package_id: 999_999, registry_id: @registry.id)
dangling_version.save(validate: false)
get versions_api_v1_registry_path(id: @registry.name)
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal 1, actual_response.length
first_version = actual_response.first
assert_equal first_version['number'], '1.0.0'
assert_equal first_version['metadata'], { 'foo' => 'bar' }
end
test 'get version numbers' do
get version_numbers_api_v1_registry_package_path(registry_id: @registry.name, id: @package.name)
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal actual_response, ["1.0.0"]
end
test 'get codemeta for a version' do
get codemeta_api_v1_registry_package_version_path(registry_id: @registry.name, package_id: @package.name, id: '1.0.0')
assert_response :success
assert_template 'versions/codemeta', file: 'versions/codemeta.json.jbuilder'
actual_response = Oj.load(@response.body)
assert_equal actual_response['@context'], 'https://w3id.org/codemeta/3.0'
assert_equal actual_response['@type'], 'SoftwareSourceCode'
assert_equal actual_response['identifier'], @version.purl
assert_equal actual_response['name'], @package.name
assert_equal actual_response['version'], '1.0.0'
assert_equal actual_response['softwareVersion'], '1.0.0'
assert_equal actual_response['applicationCategory'], @package.ecosystem
end
test 'get codemeta for version with full metadata' do
maintainer = Maintainer.create(
login: 'test-maintainer',
uuid: SecureRandom.uuid,
url: 'https://github.com/test-maintainer',
registry: @registry
)
@package.update(
description: 'A random number generator',
repository_url: 'https://github.com/rust-random/rand',
homepage: 'https://rust-random.github.io/rand',
keywords_array: ['random', 'rng'],
language: 'Rust',
normalized_licenses: ['MIT', 'Apache-2.0'],
repo_metadata: {
'html_url' => 'https://github.com/rust-random/rand',
'default_branch' => 'master',
'stargazers_count' => 500,
'forks_count' => 75,
'metadata' => {
'funding' => {
'github' => ['rust-random']
}
}
}
)
@package.maintainerships.create(maintainer: maintainer)
@version.update(
published_at: 1.year.ago,
licenses: 'MIT'
)
get codemeta_api_v1_registry_package_version_path(registry_id: @registry.name, package_id: @package.name, id: '1.0.0')
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal actual_response['@context'], 'https://w3id.org/codemeta/3.0'
assert_equal actual_response['@type'], 'SoftwareSourceCode'
assert_equal actual_response['name'], 'rand'
assert_equal actual_response['description'], 'A random number generator'
assert_equal actual_response['version'], '1.0.0'
assert_equal actual_response['softwareVersion'], '1.0.0'
assert_equal actual_response['license'], 'https://spdx.org/licenses/MIT'
assert_equal actual_response['codeRepository'], 'https://github.com/rust-random/rand'
assert_equal actual_response['issueTracker'], 'https://github.com/rust-random/rand/issues'
assert_equal actual_response['url'], 'https://rust-random.github.io/rand'
assert_equal actual_response['keywords'], ['random', 'rng']
assert_equal actual_response['programmingLanguage']['@type'], 'ComputerLanguage'
assert_equal actual_response['programmingLanguage']['name'], 'Rust'
assert_equal actual_response['maintainer'].length, 1
assert_equal actual_response['maintainer'].first['@type'], 'Person'
assert_equal actual_response['maintainer'].first['name'], 'test-maintainer'
assert_equal actual_response['maintainer'].first['url'], 'https://github.com/test-maintainer'
assert_equal actual_response['author'].length, 1
assert_equal actual_response['copyrightHolder'].length, 1
assert_equal actual_response['copyrightYear'], 1.year.ago.year
assert_equal actual_response['applicationCategory'], 'cargo'
assert_equal actual_response['runtimePlatform'], 'cargo'
assert_equal actual_response['developmentStatus'], 'active'
assert_equal actual_response['funder'].length, 1
assert_equal actual_response['funder'].first['url'], 'https://github.com/sponsors/rust-random'
assert_equal actual_response['https://www.w3.org/ns/activitystreams#likes'], 500
assert_equal actual_response['https://forgefed.org/ns#forks'], 75
end
test 'get version numbers for pypi package with underscore in name' do
get version_numbers_api_v1_registry_package_path(registry_id: @pypi_registry.name, id: 'tomli_w')
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal actual_response, ['1.0.0']
end
test 'get version numbers for pypi package with hyphen in name' do
get version_numbers_api_v1_registry_package_path(registry_id: @pypi_registry.name, id: 'tomli-w')
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal actual_response, ['1.0.0']
end
test 'list versions for pypi package with underscore in name' do
get api_v1_registry_package_versions_path(registry_id: @pypi_registry.name, package_id: 'tomli_w')
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal actual_response.length, 2
assert_equal actual_response.first['number'], '1.0.0'
end
test 'get version of pypi package with underscore in name' do
get api_v1_registry_package_version_path(registry_id: @pypi_registry.name, package_id: 'tomli_w', id: '1.0.0')
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal actual_response['number'], '1.0.0'
end
test 'get codemeta for pypi package with underscore in name' do
get codemeta_api_v1_registry_package_version_path(registry_id: @pypi_registry.name, package_id: 'tomli_w', id: '1.0.0')
assert_response :success
actual_response = Oj.load(@response.body)
assert_equal actual_response['name'], 'tomli-w'
assert_equal actual_response['version'], '1.0.0'
end
end