<commit_before>require 'rails_helper'

RSpec.describe 'GraphQL query:', type: :graphql do
  describe 'member' do
    subject(:result) { LiveLogSchema.execute(query, variables: variables, context: context) }

    let(:query) do
      <<~GRAPHQL
        query($id: ID!) {
          member(id: $id) {
            id
            joinedYear
            name
            url
            bio
            avatarUrl
            playedInstruments
            playedSongs {
              edges {
                instrument
                node {
                  id
                }
              }
            }
          }
        }
      GRAPHQL
    end
    let(:variables) { { id: member.id } }
    let(:context) { graphql_context }

    let(:member) { create(:member) }
    let!(:play) { create(:play, member: member) }

    it 'returns Member' do
      expected_data = {
        member: {
          id: member.id.to_s,
          joinedYear: member.joined_year,
          name: member.name,
          url: member.url,
          bio: member.bio,
          avatarUrl: member.avatar ? String : nil,
          playedInstruments: Array,
          playedSongs: {
            edges: [
              {
                instrument: play.instrument,
                node: {
                  id: play.song.id.to_s,
                },
              },
            ],
          },
        },
      }

      expect(result.keys).to contain_exactly 'data'
      expect(result['data']).to match expected_data.deep_stringify_keys
    end
  end
end<commit_msg>Improve spec for GraphQL query: member<commit_after>require 'rails_helper'

RSpec.describe 'GraphQL query:', type: :graphql do
  describe 'member' do
    subject(:result) { LiveLogSchema.execute(query, variables: variables, context: context) }

    let(:query) do
      <<~GRAPHQL
        query($id: ID!) {
          member(id: $id) {
            id
            joinedYear
            name
            url
            bio
            avatarUrl
            playedInstruments
            playedSongs {
              edges {
                instrument
                node {
                  id
                }
              }
            }
          }
        }
      GRAPHQL
    end
    let(:variables) { { id: member.id } }
    let(:context) { graphql_context }

    let(:member) { create(:member, avatar: create(:avatar)) }
    let!(:play) { create(:play, member: member) }

    it 'returns Member' do
      expected_data = {
        member: {
          id: member.id.to_s,
          joinedYear: member.joined_year,
          name: member.name,
          url: member.url,
          bio: member.bio,
          avatarUrl: member.avatar.image_url(64),
          playedInstruments: Array,
          playedSongs: {
            edges: [
              {
                instrument: play.instrument,
                node: {
                  id: play.song.id.to_s,
                },
              },
            ],
          },
        },
      }

      expect(result.keys).to contain_exactly 'data'
      expect(result['data']).to match expected_data.deep_stringify_keys
    end
  end
end
{'fraction_non_alphanumeric': 0.10022414345180916, 'fraction_numerical': 0.0006404098623118795, 'mean_word_length': 1.2753095411507647, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '1768232', 'n_tokens_mistral': 893, 'n_tokens_neox': 855, 'n_words': 178}