Sha256: 6fd0d11bde262555548312a95459fed367cd622ab3e80f3ba12a2aa09d745d6c

Contents?: true

Size: 950 Bytes

Versions: 10

Compression:

Stored size: 950 Bytes

Contents

# frozen_string_literal: true
require 'test_helper'

module Shipit
  class ApiClientTest < ActiveSupport::TestCase
    setup do
      @client = shipit_api_clients(:spy)
    end

    test "#authentication_token is the signed id" do
      assert_match(/^\d+--[\da-f]{40}$/, @client.authentication_token)
    end

    test "#authentication_token casted as integer is the client id" do
      assert_equal @client.id, @client.authentication_token.to_i
    end

    test ".authenticate returns nil if the signature is invalid" do
      assert_nil ApiClient.authenticate("#{@client.id}--foobar")
    end

    test ".authenticate returns nil if the api client do not exists" do
      assert_nil ApiClient.authenticate(ApiClient.new(id: 42).authentication_token)
    end

    test ".authenticate returns the matching ApiClient record if the token is valid" do
      assert_equal @client, ApiClient.authenticate(@client.authentication_token)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shipit-engine-0.39.0 test/models/api_client_test.rb
shipit-engine-0.38.0 test/models/api_client_test.rb
shipit-engine-0.37.0 test/models/api_client_test.rb
shipit-engine-0.36.1 test/models/api_client_test.rb
shipit-engine-0.36.0 test/models/api_client_test.rb
shipit-engine-0.35.1 test/models/api_client_test.rb
shipit-engine-0.35.0 test/models/api_client_test.rb
shipit-engine-0.34.0 test/models/api_client_test.rb
shipit-engine-0.33.0 test/models/api_client_test.rb
shipit-engine-0.32.0 test/models/api_client_test.rb