|
| 1 | +# -*- encoding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2015 North Development AB |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +require 'spec_helper' |
| 18 | + |
| 19 | +module PuppetForgeServer::App |
| 20 | + describe Version1 do |
| 21 | + let(:backend) { double() } |
| 22 | + let(:app) { PuppetForgeServer::App::Version1.new([backend]) } |
| 23 | + let(:module_author) { 'bogus_author' } |
| 24 | + let(:module_name) { 'bogus_name' } |
| 25 | + let(:module_string) { "#{module_author}/#{module_name}" } |
| 26 | + let(:module_deps) { [ PuppetForgeServer::Models::Dependency.new({:name => 'bogus_dep1'})] } |
| 27 | + let(:module_metadata) { PuppetForgeServer::Models::Metadata.new({:author => module_author, :name => module_name, :dependencies => module_deps}) } |
| 28 | + let(:module_hash) { { :metadata => module_metadata, :checksum => nil, :path => nil} } |
| 29 | + let(:backend_module) { PuppetForgeServer::Models::Module.new(module_hash) } |
| 30 | + |
| 31 | + before(:each) do |
| 32 | + allow(backend).to receive(:get_metadata).with(module_author, module_name, {:version => nil, :with_checksum => false}) { backend_module } |
| 33 | + allow(backend).to receive(:query_metadata).with(module_string, {:with_checksum => false}) { backend_module } |
| 34 | + end |
| 35 | + |
| 36 | + describe '#get /api/v1/releases.json' do |
| 37 | + it 'should get bogus release json' do |
| 38 | + get '/api/v1/releases.json', params={ :module => module_string } |
| 39 | + expect(last_response).to be_ok |
| 40 | + expect(JSON.parse(last_response.body).keys.first).to eq(module_string) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + describe '#get /modules.json' do |
| 45 | + it 'should get bogus modules json' do |
| 46 | + get '/modules.json', params={ :q => module_string } |
| 47 | + expect(last_response).to be_ok |
| 48 | + module_hash = JSON.parse(last_response.body).first |
| 49 | + |
| 50 | + expect(module_hash['author']).to eq(module_author) |
| 51 | + expect(module_hash['full_name']).to eq(module_name) |
| 52 | + expect(module_hash['name']).to eq(module_name) |
| 53 | + expect(module_hash['tag_list']).to eq([module_author, module_name]) |
| 54 | + expect(module_hash['private']).not_to be |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | +end |
0 commit comments