From 990ae10399ba37e211c6e23658b7ba9491eb77c0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 2 Jun 2021 15:16:35 +0200 Subject: [PATCH] GraphQL byte_size should be BigInt --- app/graphql/schema.graphql | 3 +- app/graphql/types/file.rb | 3 +- app/services/serializer_service.rb | 2 +- .../api/v2/graphql_controller_spec.rb | 67 +++++++++++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index da40645a5..a4820a002 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -1131,7 +1131,8 @@ type Entreprise { } type File { - byteSize: Int! + byteSize: Int! @deprecated(reason: "Utilisez le champ `byteSizeBigInt` à la place.") + byteSizeBigInt: BigInt! checksum: String! contentType: String! filename: String! diff --git a/app/graphql/types/file.rb b/app/graphql/types/file.rb index 0fc4cf1bd..22a8e1afd 100644 --- a/app/graphql/types/file.rb +++ b/app/graphql/types/file.rb @@ -2,7 +2,8 @@ module Types class File < Types::BaseObject field :url, Types::URL, null: false field :filename, String, null: false - field :byte_size, Int, null: false + field :byte_size, Int, null: false, deprecation_reason: "Utilisez le champ `byteSizeBigInt` à la place." + field :byte_size_big_int, GraphQL::Types::BigInt, null: false, method: :byte_size field :checksum, String, null: false field :content_type, String, null: false diff --git a/app/services/serializer_service.rb b/app/services/serializer_service.rb index 04d816f3c..3ded29254 100644 --- a/app/services/serializer_service.rb +++ b/app/services/serializer_service.rb @@ -232,7 +232,7 @@ class SerializerService fragment FileFragment on File { filename checksum - byteSize + byteSize: byteSizeBigInt contentType } GRAPHQL diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index e732ec43a..8e2a3ae0b 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -649,6 +649,73 @@ describe API::V2::GraphqlController do end end + context "champ" do + let(:champ) { create(:champ_piece_justificative, dossier: dossier) } + let(:byte_size) { 2712286911 } + + context "byteSize" do + let(:query) do + "{ + dossier(number: #{dossier.id}) { + champs(id: \"#{champ.to_typed_id}\") { + ... on PieceJustificativeChamp { + file { byteSize } + } + } + } + }" + end + + it { + expect(gql_errors).to be_nil + expect(gql_data).to eq(dossier: { champs: [{ file: { byteSize: 4 } }] }) + } + end + + context "when file is really big" do + before do + champ.piece_justificative_file.blob.update(byte_size: byte_size) + end + + context "byteSize" do + let(:query) do + "{ + dossier(number: #{dossier.id}) { + champs(id: \"#{champ.to_typed_id}\") { + ... on PieceJustificativeChamp { + file { byteSize } + } + } + } + }" + end + + it { + expect(gql_errors).not_to be_nil + } + end + + context "byteSizeBigInt" do + let(:query) do + "{ + dossier(number: #{dossier.id}) { + champs(id: \"#{champ.to_typed_id}\") { + ... on PieceJustificativeChamp { + file { byteSizeBigInt } + } + } + } + }" + end + + it { + expect(gql_errors).to be_nil + expect(gql_data).to eq(dossier: { champs: [{ file: { byteSizeBigInt: '2712286911' } }] }) + } + end + end + end + context "groupeInstructeur" do let(:groupe_instructeur) { procedure.groupe_instructeurs.first } let(:query) do