<commit_before>require 'MrMurano/version'
require 'MrMurano/Product'

RSpec.describe MrMurano::ProductContent, "#product_content" do
  before(:example) do
    $cfg = MrMurano::Config.new
    $cfg.load
    $cfg['net.host'] = 'bizapi.hosted.exosite.io'
    $cfg['product.id'] = 'XYZ'

    @prd = MrMurano::ProductContent.new
    allow(@prd).to receive(:token).and_return("TTTTTTTTTT")

    @urlroot = "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/provision/manage/content/XYZ"
  end

  it "lists nothing" do
    stub_request(:get, @urlroot + "/").
      with(headers: {'Authorization'=>'token TTTTTTTTTT',
                      'Content-Type'=>'application/json'}).
      to_return(body: "")

    ret = @prd.list
    expect(ret).to eq([])
  end

  it "creates an item" do
    stub_request(:post, @urlroot + "/").
      with(headers: {'Authorization'=>'token TTTTTTTTTT',
                      'Content-Type'=>'application/x-www-form-urlencoded'}).
      with(body: {'id'=>'testFor', 'meta'=> 'some meta'}).
      to_return(status: 205)

    ret = @prd.create("testFor", "some meta")
    expect(ret).to eq({})
  end

  it "removes an item" do
    stub_request(:post, @urlroot + "/").
      with(headers: {'Authorization'=>'token TTTTTTTTTT',
                      'Content-Type'=>'application/x-www-form-urlencoded'}).
      with(body: {'id'=>'testFor', 'delete'=>'true'}).
      to_return(status: 205)

    ret = @prd.remove("testFor")
    expect(ret).to eq({})
  end

  it "gets info for content" do
    stub_request(:get, @urlroot + "/testFor").
      with(headers: {'Authorization'=>'token TTTTTTTTTT',
                      'Content-Type'=>'application/json'}).
      to_return(body: "text/plain,42,123456789,test meta,false")

    ret = @prd.info("testFor")
    expect(ret).to eq([['text/plain','42','123456789','test meta','false']])
  end

  it "removes content" do
    stub_request(:delete, @urlroot + "/testFor").
      with(headers: {'Authorization'=>'token T<PASSWORD>',
                      'Content-Type'=>'application/json'}).
      to_return(status: 205)

    ret = @prd.remove_content("testFor")
    expect(ret).to eq({})
  end

  it "uploads content data" do
    size = FileTest.size('spec/fixtures/product_spec_files/lightbulb.yaml')
    stub_request(:post, @urlroot + "/testFor").
      with(headers: {'Authorization'=>'token <PASSWORD>',
                      'Content-Type'=>'text/yaml',
                      'Content-Length' => size
    }).
      to_return(status: 205)

    ret = @prd.upload('testFor', 'spec/fixtures/product_spec_files/lightbulb.yaml')
    expect(ret).to eq({})<commit_msg>sometimes, it is text/x-yaml<commit_after>require 'MrMurano/version'
require 'MrMurano/Product'

RSpec.describe MrMurano::ProductContent, "#product_content" do
  before(:example) do
    $cfg = MrMurano::Config.new
    $cfg.load
    $cfg['net.host'] = 'bizapi.hosted.exosite.io'
    $cfg['product.id'] = 'XYZ'

    @prd = MrMurano::ProductContent.new
    allow(@prd).to receive(:token).and_return("TTTTTTTTTT")

    @urlroot = "https://bizapi.hosted.exosite.io/api:1/product/XYZ/proxy/provision/manage/content/XYZ"
  end

  it "lists nothing" do
    stub_request(:get, @urlroot + "/").
      with(headers: {'Authorization'=>'token T<PASSWORD>TTTTT',
                      'Content-Type'=>'application/json'}).
      to_return(body: "")

    ret = @prd.list
    expect(ret).to eq([])
  end

  it "creates an item" do
    stub_request(:post, @urlroot + "/").
      with(headers: {'Authorization'=>'token T<PASSWORD>',
                      'Content-Type'=>'application/x-www-form-urlencoded'}).
      with(body: {'id'=>'testFor', 'meta'=> 'some meta'}).
      to_return(status: 205)

    ret = @prd.create("testFor", "some meta")
    expect(ret).to eq({})
  end

  it "removes an item" do
    stub_request(:post, @urlroot + "/").
      with(headers: {'Authorization'=>'token T<PASSWORD>',
                      'Content-Type'=>'application/x-www-form-urlencoded'}).
      with(body: {'id'=>'testFor', 'delete'=>'true'}).
      to_return(status: 205)

    ret = @prd.remove("testFor")
    expect(ret).to eq({})
  end

  it "gets info for content" do
    stub_request(:get, @urlroot + "/testFor").
      with(headers: {'Authorization'=>'token T<PASSWORD>',
                      'Content-Type'=>'application/json'}).
      to_return(body: "text/plain,42,123456789,test meta,false")

    ret = @prd.info("testFor")
    expect(ret).to eq([['text/plain','42','123456789','test meta','false']])
  end

  it "removes content" do
    stub_request(:delete, @urlroot + "/testFor").
      with(headers: {'Authorization'=>'token T<PASSWORD>',
                      'Content-Type'=>'application/json'}).
      to_return(status: 205)

    ret = @prd.remove_content("testFor")
    expect(ret).to eq({})
  end

  it "uploads content data" do
    size = FileTest.size('spec/fixtures/product_spec_files/lightbulb.yaml')
    stub_request(:post, @urlroot + "/testFor").
      with(headers: {'Authorization'=>'token T<PASSWORD>',
                      'Content-Type'=>/text\/(x-)?yaml/,
                      'Content-Length' => size
    }).
      to_return(status: 205)

    ret = @prd.upload('testFor', 'spec/fixtures/product_spec_files/lightbulb.yaml')
    expect(ret).to eq({})
{'fraction_non_alphanumeric': 0.18436494416051485, 'fraction_numerical': 0.013250047321597578, 'mean_word_length': 3.0521472392638036, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '6409310', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1768, 'n_words': 300}