<commit_before>require_relative '../test_helper'

class ArtefactsAPITest < ActiveSupport::TestCase

  setup do
    create_test_user
  end

  context "registering an artefact in panopticon" do
    context "for a new artefact" do
      should "create a new artefact" do
        artefact_data = {
          'slug' => 'wibble',
          'name' => 'Wibble',
          'kind' => 'answer',
          'description' => 'Wibble description',
          'owning_app' => 'publisher',
          'rendering_app' => 'frontend',
          'state' => 'draft',
          'need_extended_font' => false
        }

        # Rack::Test put method calls to_json on whatever body you pass.
        # This is different to the post method.  Go figure.
        put "/artefacts/wibble.json", artefact_data

        assert_equal 201, last_response.status
<commit_msg>Added a test around GET /artefact json api<commit_after>require_relative '../test_helper'

class ArtefactsAPITest < ActiveSupport::TestCase

  setup do
    create_test_user
  end

  context "show artefact" do
    should "return the JSON representation of the artefact" do
      artefact = FactoryGirl.create(:artefact, :slug => 'wibble', :name => "Wibble", :need_ids => ["100001", "100002"])

      get "/artefacts/wibble.json"

      assert_equal 200, last_response.status
      response = JSON.parse last_response.body

      assert_equal 'wibble', artefact["slug"]
      assert_equal 'Wibble', artefact["name"]
      assert_equal 'answer', artefact["kind"]
      assert_equal 'publisher', artefact["owning_app"]
      assert_equal 'draft', artefact["state"]
      assert_equal ['100001', '100002'], artefact["need_ids"]
    end
  end

  context "registering an artefact in panopticon" do
    context "for a new artefact" do
      should "create a new artefact" do
        artefact_data = {
          'slug' => 'wibble',
          'name' => 'Wibble',
          'kind' => 'answer',
          'description' => 'Wibble description',
          'owning_app' => 'publisher',
          'rendering_app' => 'frontend',
          'state' => 'draft',
          'need_extended_font' => false
        }

        # Rack::Test put method calls to_json on whatever body you pass.
        # This is different to the post method.  Go figure.
        put "/artefacts/wibble.json", artefact_data

        assert_equal 201, last_response.status

{'fraction_non_alphanumeric': 0.11247357293868922, 'fraction_numerical': 0.013953488372093023, 'mean_word_length': 2.6625386996904026, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3732927', 'n_tokens_mistral': 746, 'n_tokens_neox': 718, 'n_words': 200}