<commit_before># frozen_string_literal: true

require 'rails_helper'
require 'shared/api/v1/shared_expectations'

RSpec.describe Api::V2::TeamsController, type: :request do
  include RequestHelpers

  describe 'GET api/v2/teams/me' do
    let(:application) { create(:application) }
    let(:team) { create(:team) }
    let(:team2) { create :team, name: 'The Company', slug: 'the-company' }
    let(:team3) { create :team, name: 'The Invited', slug: 'the-invited' }
    let(:team4) { create :team, name: 'The Second Invited', slug: 'the-second-invited' }
    let(:user) { create(:user) }
    let(:token) do
      Doorkeeper::AccessToken.create! application_id: application.id,
                                      resource_owner_id: user.id
    end
    let!(:invite) { TeamInvite.create(user: user, team: team3) }
    let!(:invite2) { TeamInvite.create(user: user, team: team4, accepted_at: Time.now) }
    let(:request) { '/api/v2/teams/me' }

    before do
      team.add_member(user)
      team2.add_member(user)
    end

    context 'with a valid api-token' do
      before do
        get request, format: :json, access_token: token.token
      end

      it 'returns a list of teams and one invite' do
        expected =
          {
            data: {
              amountOfTeams: 2,
              teams: [
                {
                  id: team.id,
                  name: team.name,
                  slug: team.slug,
                  logo: ''
                },
                {
                  id: team2.id,
                  name: team2.name,
                  slug: team2.slug,<commit_msg>Added check for declined invite as well<commit_after># frozen_string_literal: true

require 'rails_helper'
require 'shared/api/v1/shared_expectations'

RSpec.describe Api::V2::TeamsController, type: :request do
  include RequestHelpers

  describe 'GET api/v2/teams/me' do
    let(:application) { create(:application) }
    let(:team) { create(:team) }
    let(:team2) { create :team, name: 'The Company', slug: 'the-company' }
    let(:team3) { create :team, name: 'The Invited', slug: 'the-invited' }
    let(:team4) { create :team, name: 'The Second Invited', slug: 'the-second-invited' }
    let(:team5) { create :team, name: 'The Third Invited', slug: 'the-third-invited' }
    let(:user) { create(:user) }
    let(:token) do
      Doorkeeper::AccessToken.create! application_id: application.id,
                                      resource_owner_id: user.id
    end
    let!(:invite) { TeamInvite.create(user: user, team: team3) }
    let!(:invite2) { TeamInvite.create(user: user, team: team4, accepted_at: Time.now) }
    let!(:invite3) { TeamInvite.create(user: user, team: team5, declined_at: Time.now) }
    let(:request) { '/api/v2/teams/me' }

    before do
      team.add_member(user)
      team2.add_member(user)
    end

    context 'with a valid api-token' do
      before do
        get request, format: :json, access_token: token.token
      end

      it 'returns a list of teams and one invite' do
        expected =
          {
            data: {
              amountOfTeams: 2,
              teams: [
                {
                  id: team.id,
                  name: team.name,
                  slug: team.slug,
                  logo: ''
                },
                {
                  id: team2.id,
                  name: team2.name,
                  slug: team2.slug,
{'fraction_non_alphanumeric': 0.12295560747663552, 'fraction_numerical': 0.009637850467289719, 'mean_word_length': 1.9808529155787642, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1681958', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1063, 'n_words': 259}