Sha256: 88819fd58820a8cffd2a746f23aa4e948b5887f0f3e55af7dff06b0d43b117be

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

# Import the RSpec and VCR gems
require 'spec_helper'
require 'vcr'
require 'json'

# require "webmock/rspec"
# Import the `Fields` class

# Configure VCR to save and replay HTTP requests
VCR.configure do |config|
  config.cassette_library_dir = './fixtures'
  config.hook_into :webmock
  config.filter_sensitive_data('<AUTH>') do |interaction|
    interaction.request.headers['Authorization'][0]
  end
end

# Set up the test for the `Fields` class
RSpec.describe MailerLite::Fields do
  let(:client) { MailerLite::Client.new }
  let(:fields) { described_class.new(client: client) }

  describe '#get' do
    # Use VCR to record and replay the HTTP request
    it 'returns a list of Fields' do
      VCR.use_cassette('fields/get') do
        response = fields.get
        body = JSON.parse(response.body)
        expect(response.status).to eq 200
        expect(body['data']).to be_an Array
      end
    end
  end

  describe '#create' do
    # Use VCR to record and replay the HTTP request
    it 'creates a field' do
      VCR.use_cassette('fields/create') do
        response = fields.create(type: 'text', name: 'test_field_name')
        body = JSON.parse(response.body)
        expect(response.status).to eq 201
        expect(Integer(body['data']['id'])).to be_an Integer
      end
    end
  end

  describe '#update' do
    # Use VCR to record and replay the HTTP request
    it 'updates a field' do
      VCR.use_cassette('fields/update') do
        response = fields.update(field_id: 91_115, name: 'test_field2')
        body = JSON.parse(response.body)
        expect(response.status).to eq 200
        expect(Integer(body['data']['id'])).to be_an Integer
      end
    end
  end

  describe '#delete' do
    # Use VCR to record and replay the HTTP request
    it 'deletes a field' do
      VCR.use_cassette('fields/delete') do
        response = fields.delete(91_115)
        expect(response.status).to eq 204
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mailerlite-ruby-1.0.5 spec/fields_rspec.rb
mailerlite-ruby-1.0.4 spec/fields_rspec.rb
mailerlite-ruby-1.0.3 spec/fields_rspec.rb
mailerlite-ruby-1.0.2 spec/fields_rspec.rb