counters_spec.rb #2

  • //
  • guest/
  • doug_scheirer/
  • helix-web-services/
  • main/
  • source/
  • helix_web_services/
  • spec/
  • helix_versioning_engine/
  • counters_spec.rb
  • View
  • Commits
  • Open Download .zip Download (3 KB)
require_relative '../test_config'

require 'helix_versioning_engine'

describe 'HelixVersioningEngine counters' do
  include Rack::Test::Methods

  def app
    HELIX_WEB_SERVICES_APP
  end

  randstr = (0...8).map { (65 + rand(26)).chr }.join

  counter_1 = "#{randstr}_test_1"
  counter_2 = "#{randstr}_test_2"

  context 'PUT /p4/v78/counters/[counter]' do
    it 'can create a numerical counter' do
      authorize 'super', ticket_for_super
      put("/p4/v78/counters/#{counter_1}", value: '1')
      expect(last_response.status).to eq(200)
    end

    it 'can create a text counter' do
      authorize 'super', ticket_for_super
      put("/p4/v78/counters/#{counter_2}", value: randstr)
      expect(last_response.status).to eq(200)
    end
  end

  context 'GET /p4/v78/counters' do
    it 'can include our test counters in the list' do
      authorize 'super', ticket_for_super
      get('/p4/v78/counters')
      expect(last_response.status).to eq(200)

      counters = JSON.parse(last_response.body)
      expect(counters.map { |x| x['counter'] }).to include(counter_1)
      expect(counters.map { |x| x['counter'] }).to include(counter_2)
    end
  end

  context 'GET /p4/v78/counters/[counter]' do
    it 'can list our numerical counter' do
      authorize 'super', ticket_for_super
      get("/p4/v78/counters/#{counter_1}")
      expect(last_response.status).to eq(200)

      counter = JSON.parse(last_response.body)
      expect(counter['value']).to eq('1')
    end

    it 'can list the text counter' do
      authorize 'super', ticket_for_super
      get("/p4/v78/counters/#{counter_2}")
      expect(last_response.status).to eq(200)

      counter = JSON.parse(last_response.body)
      expect(counter['value']).to eq(randstr)
    end
  end

  context 'POST /p4/v78/counters/[counter]/increment' do
    it 'can increment the numerical counter' do
      authorize 'super', ticket_for_super
      post("/p4/v78/counters/#{counter_1}/increment")
      expect(last_response.status).to eq(200)

      get("/p4/v78/counters/#{counter_1}")
      expect(last_response.status).to eq(200)
      counter = JSON.parse(last_response.body)
      expect(counter['value']).to eq('2')
    end
  end

  context 'DELETE /p4/v78/counters/[counter]' do
    it 'can delete our test counters' do
      authorize 'super', ticket_for_super
      delete("/p4/v78/counters/#{counter_1}")
      delete("/p4/v78/counters/#{counter_2}")
      expect(last_response.status).to eq(200)

      get('/p4/v78/counters')
      expect(last_response.status).to eq(200)

      counters = JSON.parse(last_response.body)
      expect(counters.map { |x| x['counter'] }).to_not include(counter_1)
      expect(counters.map { |x| x['counter'] }).to_not include(counter_2)

    end
  end

end
# Change User Description Committed
#2 16114 Doug Scheirer Merge from main
#1 15688 Doug Scheirer Populate -o //guest/perforce_software/helix-web-services/...
//guest/doug_scheirer/helix-web-services/....
//guest/perforce_software/helix-web-services/main/source/helix_web_services/spec/helix_versioning_engine/counters_spec.rb
#1 15622 tjuricek Move source code to 'source/' subdirectory of branch.

build/ will remain where it is.
//guest/perforce_software/helix-web-services/main/helix_web_services/spec/helix_versioning_engine/counters_spec.rb
#3 15240 tjuricek Set api level via request path on all Helix Versioning Engine methods.

This will allow migration of applications to different P4D versions. Our internal methods (like project API) should attempt to handle backward compatibility similarly.

P4WEBAPI-118
#2 15227 tjuricek Revise implementation, tests, and documentation for protections management.

Remove some specs I will not be revising from the helix_web_services project.
#1 15225 tjuricek Revise counter implementation, tests, and documentation

Wasn't available in the Ruby client before, so, it's now available.