2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-17 12:27:30 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
describe BlobViewer::PackageJson do
|
2017-05-17 12:27:30 -04:00
|
|
|
include FakeBlobHelpers
|
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { build_stubbed(:project) }
|
2017-05-17 12:27:30 -04:00
|
|
|
let(:data) do
|
|
|
|
<<-SPEC.strip_heredoc
|
|
|
|
{
|
|
|
|
"name": "module-name",
|
|
|
|
"version": "10.3.1"
|
|
|
|
}
|
|
|
|
SPEC
|
|
|
|
end
|
|
|
|
let(:blob) { fake_blob(path: 'package.json', data: data) }
|
2019-12-18 19:08:01 -05:00
|
|
|
|
2017-05-17 12:27:30 -04:00
|
|
|
subject { described_class.new(blob) }
|
|
|
|
|
|
|
|
describe '#package_name' do
|
|
|
|
it 'returns the package name' do
|
|
|
|
expect(subject).to receive(:prepare!)
|
|
|
|
|
|
|
|
expect(subject.package_name).to eq('module-name')
|
|
|
|
end
|
|
|
|
end
|
2017-12-18 23:55:51 -05:00
|
|
|
|
|
|
|
describe '#package_url' do
|
|
|
|
it 'returns the package URL' do
|
|
|
|
expect(subject).to receive(:prepare!)
|
|
|
|
|
|
|
|
expect(subject.package_url).to eq("https://www.npmjs.com/package/#{subject.package_name}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#package_type' do
|
|
|
|
it 'returns "package"' do
|
|
|
|
expect(subject).to receive(:prepare!)
|
|
|
|
|
|
|
|
expect(subject.package_type).to eq('package')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when package.json has "private": true' do
|
2018-09-12 02:34:55 -04:00
|
|
|
let(:homepage) { 'http://example.com' }
|
2017-12-18 23:55:51 -05:00
|
|
|
let(:data) do
|
|
|
|
<<-SPEC.strip_heredoc
|
|
|
|
{
|
|
|
|
"name": "module-name",
|
|
|
|
"version": "10.3.1",
|
2017-12-19 00:14:08 -05:00
|
|
|
"private": true,
|
2018-09-12 02:34:55 -04:00
|
|
|
"homepage": #{homepage.to_json}
|
2017-12-18 23:55:51 -05:00
|
|
|
}
|
|
|
|
SPEC
|
|
|
|
end
|
|
|
|
let(:blob) { fake_blob(path: 'package.json', data: data) }
|
2019-12-18 19:08:01 -05:00
|
|
|
|
2017-12-18 23:55:51 -05:00
|
|
|
subject { described_class.new(blob) }
|
|
|
|
|
|
|
|
describe '#package_url' do
|
2018-09-12 02:34:55 -04:00
|
|
|
context 'when the homepage has a valid URL' do
|
|
|
|
it 'returns homepage URL' do
|
|
|
|
expect(subject).to receive(:prepare!)
|
|
|
|
|
|
|
|
expect(subject.package_url).to eq(homepage)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the homepage has an invalid URL' do
|
|
|
|
let(:homepage) { 'javascript:alert()' }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject).to receive(:prepare!)
|
2017-12-18 23:55:51 -05:00
|
|
|
|
2018-09-12 02:34:55 -04:00
|
|
|
expect(subject.package_url).to be_nil
|
|
|
|
end
|
2017-12-18 23:55:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#package_type' do
|
|
|
|
it 'returns "private package"' do
|
|
|
|
expect(subject).to receive(:prepare!)
|
|
|
|
|
|
|
|
expect(subject.package_type).to eq('private package')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-17 12:27:30 -04:00
|
|
|
end
|