Merge pull request #3392 from okriuchykhin/ok_SCI_5816

Fix API date time serializers [SCI-5816]
This commit is contained in:
Alex Kriuchykhin 2021-06-16 12:28:16 +02:00 committed by GitHub
commit 1e830a49f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 72 additions and 30 deletions

View file

@ -3,7 +3,14 @@
module Api
module V1
class RepositoryDateRangeValueSerializer < ActiveModel::Serializer
attribute :formatted, key: :date_range
attribute :date_range
def date_range
{
from: object.start_time.to_date,
to: object.end_time.to_date
}
end
end
end
end

View file

@ -3,7 +3,14 @@
module Api
module V1
class RepositoryDateTimeRangeValueSerializer < ActiveModel::Serializer
attribute :formatted, key: :date_time_range
attribute :date_time_range
def date_time_range
{
from: object.start_time,
to: object.end_time
}
end
end
end
end

View file

@ -3,7 +3,11 @@
module Api
module V1
class RepositoryDateTimeValueSerializer < ActiveModel::Serializer
attribute :formatted, key: :date_time
attribute :date_time
def date_time
object.data
end
end
end
end

View file

@ -3,7 +3,11 @@
module Api
module V1
class RepositoryDateValueSerializer < ActiveModel::Serializer
attribute :formatted, key: :date
attribute :date
def date
object.data.to_date
end
end
end
end

View file

@ -3,7 +3,14 @@
module Api
module V1
class RepositoryTimeRangeValueSerializer < ActiveModel::Serializer
attribute :formatted, key: :time_range
attribute :time_range
def time_range
{
from: object.start_time.strftime('%H:%M:%S.%3NZ'),
to: object.start_time.strftime('%H:%M:%S.%3NZ')
}
end
end
end
end

View file

@ -3,7 +3,11 @@
module Api
module V1
class RepositoryTimeValueSerializer < ActiveModel::Serializer
attribute :formatted, key: :time
attribute :time
def time
object.data.strftime('%H:%M:%S.%3NZ')
end
end
end
end

View file

@ -369,10 +369,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
), headers: @valid_headers
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells,
each_serializer: Api::V1::InventoryCellSerializer)
.as_json[:data]
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells, each_serializer: Api::V1::InventoryCellSerializer)
.to_json
)['data']
)
end
@ -548,10 +549,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
expect(response).to have_http_status 201
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
ActiveModelSerializers::SerializableResource
.new(RepositoryCell.last,
serializer: Api::V1::InventoryCellSerializer)
.as_json[:data]
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer)
.to_json
)['data']
)
end
@ -602,10 +604,11 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
expect(response).to have_http_status 201
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
ActiveModelSerializers::SerializableResource
.new(RepositoryCell.last,
serializer: Api::V1::InventoryCellSerializer)
.as_json[:data]
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(RepositoryCell.last, serializer: Api::V1::InventoryCellSerializer)
.to_json
)['data']
)
end
@ -836,10 +839,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
expect(response).to have_http_status 200
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells.where(repository_column: @date_column).first,
serializer: Api::V1::InventoryCellSerializer)
.as_json[:data]
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells.where(repository_column: @date_column).first,
serializer: Api::V1::InventoryCellSerializer)
.to_json
)['data']
)
end
@ -872,10 +877,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
expect(response).to have_http_status 200
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells.where(repository_column: @date_time_column).first,
serializer: Api::V1::InventoryCellSerializer)
.as_json[:data]
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells.where(repository_column: @date_time_column).first,
serializer: Api::V1::InventoryCellSerializer)
.to_json
)['data']
)
end
@ -890,10 +897,12 @@ RSpec.describe 'Api::V1::InventoryCellsController', type: :request do
expect(response).to have_http_status 200
expect { hash_body = json }.not_to raise_exception
expect(hash_body[:data]).to match(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells.where(repository_column: @date_range_column).first,
serializer: Api::V1::InventoryCellSerializer)
.as_json[:data]
JSON.parse(
ActiveModelSerializers::SerializableResource
.new(@valid_item.repository_cells.where(repository_column: @date_range_column).first,
serializer: Api::V1::InventoryCellSerializer)
.to_json
)['data']
)
end