1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

Merge branch 'uvsq' into dev

This commit is contained in:
Sylvain 2019-10-01 14:32:58 +02:00
commit 29d6a1daa4
9 changed files with 185 additions and 16 deletions

View File

@ -37,6 +37,7 @@
.text-blue { color: $blue; }
.text-muted { color: $text-muted; }
.text-danger, .red { color: $red !important; }
.text-red-only { color: $red !important; }
.text-purple { color: $violet !important; }
.text-japonica { color: $japonica !important; }
.text-beige { color: $beige !important; }

View File

@ -46,7 +46,7 @@
<i class="fa fa-check-square-o fa-stack-outside"></i>
<span class="m-l" translate>{{ 'members_import_result.success' }}</span>
</span>
<span ng-hide="resultRow.result" class="red font-bold">
<span ng-hide="resultRow.result" class="text-red-only font-bold">
<span class="fa-stack v-bottom">
<i class="fa fa-square-o fa-stack-1x fa-stack-outside"></i>
<i class="fa fa-times fa-stack-1x fa-stack-inside"></i>
@ -54,7 +54,7 @@
<span class="m-l" translate>{{ 'members_import_result.failed' }}</span>
</span>
</div>
<div class="m-l-lg red" ng-if="!resultRow.row && !resultRow.status">
<div class="m-l-lg text-red-only" ng-if="!resultRow.row && !resultRow.status">
<span class="m-r" translate>{{ 'members_import_result.error_details' }}</span>{{resultRow}}
</div>
</div>

View File

@ -22,7 +22,7 @@ class Members::ImportService
user = User.new(params)
service = Members::MembersService.new(user)
res = service.create(import.user, params)
log << { user: nil, status: 'create', result: res }
log << { user: user.id, status: 'create', result: res }
end
log << user.errors.to_hash unless user.errors.to_hash.empty?
rescue StandardError => e

View File

@ -15,8 +15,8 @@ ActiveRecord::Schema.define(version: 20190924140726) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "pg_trgm"
enable_extension "unaccent"
enable_extension "pg_trgm"
create_table "abuses", force: :cascade do |t|
t.integer "signaled_id"

6
test/fixtures/files/members.csv vendored Normal file
View File

@ -0,0 +1,6 @@
id;gender;first_name;last_name;username;email;password;birthdate;address;phone;group;tags;trainings;website;job;interests;softwares;allow_contact;allow_newsletter;organization_name;organization_address;facebook;twitter;googleplus;viadeo;linkedin;instagram;youtube;vimeo;dailymotion;github;echosciences;pinterest;lastfm;flickr
;male;victor;hugo;vhugo;victor.hugo@wanadoo.fr;;1802-02-26;140 Grande Rue - 25000 Besançon;0381614214;standard;1;1,2,5;http://www.victor-hugo.info;Poète;Hacking, DIY;SolidWorks, Inkspace;yes;yes;;;http://www.facebook.com/victor-hugo;;;;;;;;;http://github.com/vhugo;;;;
;female;louise;michel;lmichel;louise.michel@gresille.org;;1830-03-29;8 rue de l'église - 52240 Vroncourt-la-Côte;0324491826;standard;2;5;https://rebellyon.info;Institutrice;militantisme;AutoCAD, LibreCAD;yes;yes;;;;;;;;;;;;http://github.com/louisemichel;https://www.echosciences-grenoble.fr/membres/louise-michel;;;
;male;ambroise;croizat;acroizat;acroizat@msn.com;;1801-01-28;cité des Maisonnettes - 73260 Notre-Dame-de-Briançon;0473147852;standard;;5;;Ouvrier;métallurgie;;no;no;;;;;;;;;https://www.youtube.com/user/croizat;;;;;;;
;female;rirette;maîtrejean;;;;1887-08-14;19330 Saint-Mexant;0555124789;standard;;;;;;;;yes;no
2;;;;;jean.dupond@yahoo.fr
1 id;gender;first_name;last_name;username;email;password;birthdate;address;phone;group;tags;trainings;website;job;interests;softwares;allow_contact;allow_newsletter;organization_name;organization_address;facebook;twitter;googleplus;viadeo;linkedin;instagram;youtube;vimeo;dailymotion;github;echosciences;pinterest;lastfm;flickr
2 ;male;victor;hugo;vhugo;victor.hugo@wanadoo.fr;;1802-02-26;140 Grande Rue - 25000 Besançon;0381614214;standard;1;1,2,5;http://www.victor-hugo.info;Poète;Hacking, DIY;SolidWorks, Inkspace;yes;yes;;;http://www.facebook.com/victor-hugo;;;;;;;;;http://github.com/vhugo;;;;
3 ;female;louise;michel;lmichel;louise.michel@gresille.org;;1830-03-29;8 rue de l'église - 52240 Vroncourt-la-Côte;0324491826;standard;2;5;https://rebellyon.info;Institutrice;militantisme;AutoCAD, LibreCAD;yes;yes;;;;;;;;;;;;http://github.com/louisemichel;https://www.echosciences-grenoble.fr/membres/louise-michel;;;
4 ;male;ambroise;croizat;acroizat;acroizat@msn.com;;1801-01-28;cité des Maisonnettes - 73260 Notre-Dame-de-Briançon;0473147852;standard;;5;;Ouvrier;métallurgie;;no;no;;;;;;;;;https://www.youtube.com/user/croizat;;;;;;;
5 ;female;rirette;maîtrejean;;;;1887-08-14;19330 Saint-Mexant;0555124789;standard;;;;;;;;yes;no
6 2;;;;;jean.dupond@yahoo.fr

View File

@ -1,9 +1,102 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
author_id: 1
user_id: 1
attachment: 'users.csv'
update_field: 'id'
category: 'members'
results: |
---
- :row:
id:
gender: male
first_name: jean
last_name: dupont
username: jdupont
email: jean.dupont@gmail.com
password:
birthdate: '1970-01-01'
address: 12 bvd Libération - 75000 Paris
phone: '0123456789'
group: standard
tags: '1,2'
trainings: '1'
website: http://www.example.com
job: Charpentier
interests: Ping-pong
softwares: AutoCAD
allow_contact: 'yes'
allow_newsletter: 'no'
organization_name:
organization_address:
facebook: http://www.facebook.com/jdupont
twitter:
googleplus:
viadeo:
linkedin:
instagram:
youtube:
vimeo:
dailymotion:
github: http://github.com/example
echosciences:
pinterest:
lastfm:
flickr:
- :user:
:status: create
:result: false
- :username:
- n'est pas disponible
- :row:
id: '43'
gender:
first_name:
last_name:
username:
email:
password: "********"
birthdate:
address:
phone:
group:
tags:
trainings:
website:
job:
interests:
softwares:
allow_contact:
allow_newsletter:
organization_name:
organization_address:
facebook:
twitter:
googleplus:
viadeo:
linkedin:
instagram:
youtube:
vimeo:
dailymotion:
github:
echosciences:
pinterest:
lastfm:
flickr:
- :user:
:status: create
:result: false
- :email:
- doit être rempli(e)
:profile.first_name:
- doit être rempli(e)
:profile.last_name:
- doit être rempli(e)
:profile.phone:
- n'est pas un nombre
:username:
- doit être rempli(e)
created_at: 2019-09-24 15:06:22.151882000 Z
updated_at: 2019-09-24 15:06:22.151882000 Z

View File

@ -0,0 +1,71 @@
# frozen_string_literal: true
class ImportTest < ActionDispatch::IntegrationTest
# Called before every test method runs. Can be used
# to set up fixture information.
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'bulk import members through CSV' do
bulk_csv = fixture_file_upload('files/members.csv', 'text/csv')
post '/api/imports/members',
{
import_members: bulk_csv,
update_field: 'id'
}, default_headers
assert_equal 201, response.status, response.body
assert_equal Mime::JSON, response.content_type
# Check that the returned import was created
import = json_response(response.body)
assert_not_nil import[:id], 'no returned id for the import'
db_import = Import.find(import[:id])
assert_not_nil db_import
# run the import synchronously
worker = MembersImportWorker.new
worker.perform(import[:id])
# check the results were written
db_import.reload
assert_not_empty db_import.results, 'import results were not written'
res = db_import.results_hash
assert_not_nil res[0][:row], 'import result does not contains the imported data row'
assert_not_nil res[1][:status], 'import result does not contains the operation applied to the row (create/update)'
assert_not_nil res[1][:result], 'import result does not contains the result of the operation'
# check the results match the expectations
assert_not_nil res[1][:user], 'wrong user: victor hugo is expected to have been created in database'
assert_equal 'create', res[1][:status], 'wrong operation: victor hugo should have been created'
assert res[1][:result], 'wrong result: operation should have succeeded'
assert_equal 1, User.where(id: res[1][:user]).count, 'victor hugo was not found in database'
assert_not_nil res[3][:user], 'wrong user: louise michel is expected to have been created in database'
assert_equal 'create', res[3][:status], 'wrong operation: louise michel should have been created'
assert res[3][:result], 'wrong result: operation should have succeeded'
assert_equal 1, User.where(id: res[3][:user]).count, 'louise michel was not found in database'
assert_not_nil res[5][:user], 'wrong user: ambroise croizat is expected to have been created in database'
assert_equal 'create', res[5][:status], 'wrong operation: ambroise croizat should have been created'
assert res[5][:result], 'wrong result: operation should have succeeded'
assert_equal 1, User.where(id: res[5][:user]).count, 'ambroise croizat was not found in database'
assert_nil res[7][:user], 'wrong user: rirette maitrejean is not expected to have been created in database'
assert_equal 'create', res[7][:status], 'wrong operation: rirette maitrejean should have been created'
assert_not res[7][:result], 'wrong result: operation should have failed'
assert_equal 0, Profile.where(last_name: res[6][:row]['last_name']).count, 'rirette maitrejean was found in database'
assert_match /can't be blank/, res[8][:email].to_json
assert_match /can't be blank/, res[8][:username].to_json
assert_not_nil res[10][:user], 'wrong user: jean dupont is expected to exists in database'
assert_equal 'update', res[10][:status], 'wrong operation: jean dupont should have been updated'
assert res[10][:result], 'wrong result: operation should have succeeded'
assert_equal res[9][:row]['email'], User.find(res[10][:user]).email, 'jean dupont email was not updated'
end
end

View File

@ -64,9 +64,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
amount = 10.5
expected_amount = w.amount + amount
put "/api/wallet/#{w.id}/credit",
{
amount: amount
}
assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type
@ -88,12 +86,10 @@ class WalletsTest < ActionDispatch::IntegrationTest
avoir_date = Time.now.end_of_day
expected_amount = w.amount + amount
put "/api/wallet/#{w.id}/credit",
{
amount: amount,
avoir: true,
avoir_date: avoir_date,
avoir_description: 'Some text'
}
amount: amount,
avoir: true,
avoir_date: avoir_date,
avoir_description: 'Some text'
assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type

View File

@ -10,6 +10,8 @@ require 'vcr'
require 'sidekiq/testing'
require 'minitest/reporters'
include ActionDispatch::TestProcess
VCR.configure do |config|
config.cassette_library_dir = 'test/vcr_cassettes'
config.hook_into :webmock
@ -92,9 +94,9 @@ class ActiveSupport::TestCase
ht_amount = parse_amount_from_invoice_line(line) if line.include? I18n.t('invoices.including_total_excluding_taxes')
end
if Setting.find_by(name: 'invoice_VAT-active').value == 'true'
vat_service = VatHistoryService.new
vat_rate = vat_service.invoice_vat(invoice)
vat_service = VatHistoryService.new
vat_rate = vat_service.invoice_vat(invoice)
if vat_rate.positive?
computed_ht = sprintf('%.2f', (invoice.total / (vat_rate / 100.00 + 1)) / 100.00).to_f
assert_equal computed_ht, ht_amount, 'Total excluding taxes rendered in the PDF file is not computed correctly'