require 'db/mongo/models/job_task'

RSpec.describe Devops::Model::JobTask, type: :model do
  let(:task) { build(:task) }

  describe '#initialize' do
    let(:given_moment) { Time.new(2007,11,1,15,25,0, "+01:00") }

    it 'converts created_at to localtime' do
      converted = build(:task, created_at: given_moment).created_at
      expect(converted).to eq 1193927100
    end

    it 'converts updated_at to localtime' do
      converted = build(:task, updated_at: given_moment).updated_at
      expect(converted).to eq 1193927100
    end
  end

  describe '#to_hash' do
    it 'returns hash with some keys' do
      expect(task.to_hash.keys).to match_array(%w(
        id
        created_at
        created_by
        project
        environment
        type
        status
        stack
        subtasks
      ))
    end

    it 'could return extra elements' do
      expect(build(:task, stack: 'my_stack').to_hash).to include('stack' => 'my_stack')
    end
  end
end
