Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tokens for groups #15

Merged
merged 30 commits into from
Apr 22, 2024
Merged

Create tokens for groups #15

merged 30 commits into from
Apr 22, 2024

Conversation

microstudi
Copy link
Contributor

@microstudi microstudi commented Apr 16, 2024

fixes #3

tests:

  • Create tokens command test
  • Create tokens form test
  • Create tokens system test

config/locales/en.yml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 98.76543% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 98.29%. Comparing base (9bc4469) to head (768798a).

Files Patch % Lines
...decidim/anonymous_codes/export_group_tokens_job.rb 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   97.18%   98.29%   +1.11%     
==========================================
  Files          21       24       +3     
  Lines         355      411      +56     
==========================================
+ Hits          345      404      +59     
+ Misses         10        7       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor Author

@microstudi microstudi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excelent Job Elvia,

left you some simple comments only.

I'd like to add a test for the CreateTokensJob, to check if an generated token is already in the database, let's make sure that it works correctly.

Here's a spec that we could be using (to be placed under spec/jobs/create_tokens_job_spec.rb):

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module AnonymousCodes
    describe CreateTokensJob do
      subject { described_class.perform_now(code_group, num_tokens) }

      let(:organization) { create(:organization) }
      let(:code_group) { create :anonymous_codes_group }
      let(:num_tokens) { 2 }
      let(:token1) { "TOKEN1" }
      let(:token2) { "TOKEN2" }
      let(:token3) { "TOKEN3" }

      before do
        allow(Decidim::AnonymousCodes).to receive(:token_generator).and_return(token1, token2, token3)
      end

      it "generates 2 tokens" do
        expect { subject }.to change { Token.count }.by(2)
        expect(Token.all.pluck(:token)).to match_array([token1, token2])
      end

      context "when token is repeated" do
        let!(:existing_token) { create(:anonymous_codes_token, token: token2, group: code_group) }

        it "skips the repeated" do
          expect { subject }.to change { Token.count }.by(2)
          expect(Token.all.pluck(:token)).to match_array([token1, token2, token3])
        end
      end
    end
  end
end

spec/commands/admin/create_tokens_spec.rb Outdated Show resolved Hide resolved
spec/commands/admin/create_tokens_spec.rb Outdated Show resolved Hide resolved
spec/controller/admin/codes_controller_spec.rb Outdated Show resolved Hide resolved
@microstudi microstudi merged commit f8119d9 into main Apr 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic generation of tokens
2 participants