From 02c72e55d962cecd97c2004c4c8af7024dab6bab Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 13 Apr 2016 10:43:25 +0200 Subject: [PATCH] test admins --- db/test_seeds.rb | 64 --------------------------------- test/integration/abuses_test.rb | 2 +- test/integration/admins_test.rb | 50 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 65 deletions(-) delete mode 100644 db/test_seeds.rb create mode 100644 test/integration/admins_test.rb diff --git a/db/test_seeds.rb b/db/test_seeds.rb deleted file mode 100644 index 1b28fc80c..000000000 --- a/db/test_seeds.rb +++ /dev/null @@ -1,64 +0,0 @@ -Group.create!([ - {name: "standard, association", slug: "standard"}, - {name: "étudiant, - de 25 ans, enseignant, demandeur d'emploi", slug: "student"}, - {name: "artisan, commerçant, chercheur, auto-entrepreneur", slug: "merchant"}, - {name: "PME, PMI, SARL, SA", slug: "business"} -]) - -if Category.count == 0 - Category.create!([ - {name: "Stage"}, - {name: "Atelier"} - ]) -end - -if StatisticIndex.count == 0 - StatisticIndex.create!([ - {id:1, es_type_key:'subscription', label:'Abonnements'}, - {id:2, es_type_key:'machine', label:'Heures machines'}, - {id:3, es_type_key:'training', label:'Formations'}, - {id:4, es_type_key:'event', label:'Ateliers/Stages'}, - {id:5, es_type_key:'account', label:'Inscriptions', ca: false}, - {id:6, es_type_key:'project', label:'Projets', ca: false}, - {id:7, es_type_key:'user', label:'Utilisateurs', table: false, ca: false} - ]) - connection = ActiveRecord::Base.connection - if connection.instance_values["config"][:adapter] == 'postgresql' - connection.execute("SELECT setval('statistic_indices_id_seq', 7);") - end -end - -if StatisticField.count == 0 - StatisticField.create!([ - # available data_types : index, number, date, text, list - {key:'trainingId', label:'ID Formation', statistic_index_id: 3, data_type: 'index'}, - {key:'trainingDate', label:'Date Formation', statistic_index_id: 3, data_type: 'date'}, - {key:'eventId', label:'ID Évènement', statistic_index_id: 4, data_type: 'index'}, - {key:'eventDate', label:'Date Évènement', statistic_index_id: 4, data_type: 'date'}, - {key:'themes', label:'Thèmes', statistic_index_id: 6, data_type: 'list'}, - {key:'components', label:'Composants', statistic_index_id: 6, data_type: 'list'}, - {key:'machines', label:'Machines', statistic_index_id: 6, data_type: 'list'}, - {key:'name', label:'Nom Évènement', statistic_index_id: 4, data_type: 'text'}, - {key:'userId', label:'ID Utilisateur', statistic_index_id: 7, data_type: 'index'} - ]) -end - -if StatisticType.count == 0 - StatisticType.create!([ - {id:1, statistic_index_id: 1, key: 'month', label:'Abonnements mensuels', graph: true, simple: true}, - {id:2, statistic_index_id: 1, key: 'year', label:'Abonnements annuels', graph: true, simple: true}, - {id:3, statistic_index_id: 2, key: 'booking', label:'Réservations', graph: true, simple: true}, - {id:4, statistic_index_id: 2, key: 'hour', label:"Nombre d'heures", graph: true, simple: false}, - {id:5, statistic_index_id: 3, key: 'booking', label:'Réservations', graph: false, simple: true}, - {id:6, statistic_index_id: 3, key: 'hour', label:"Nombre d'heures", graph: false, simple: false}, - {id:7, statistic_index_id: 4, key: 'booking', label:'Nombre de places', graph: false, simple: false}, - {id:8, statistic_index_id: 4, key: 'hour', label:"Nombre d'heures", graph: false, simple: false}, - {id:9, statistic_index_id: 5, key: 'member', label:'Utilisateurs', graph: true, simple: true}, - {id:10, statistic_index_id: 6, key: 'project', label:'Projets', graph: false, simple: true}, - {id:11, statistic_index_id: 7, key: 'revenue', label:"Chiffre d'affaires", graph: false, simple: false} - ]) - connection = ActiveRecord::Base.connection - if connection.instance_values["config"][:adapter] == 'postgresql' - connection.execute("SELECT setval('statistic_types_id_seq', 11);") - end -end diff --git a/test/integration/abuses_test.rb b/test/integration/abuses_test.rb index fd3b4a27d..2a0b5bbfe 100644 --- a/test/integration/abuses_test.rb +++ b/test/integration/abuses_test.rb @@ -15,7 +15,7 @@ class AbusesTest < ActionDispatch::IntegrationTest # Abuse report test 'visitor report an abuse' do - project = Project.first + project = Project.take post '/api/abuses', { diff --git a/test/integration/admins_test.rb b/test/integration/admins_test.rb new file mode 100644 index 000000000..8969b7697 --- /dev/null +++ b/test/integration/admins_test.rb @@ -0,0 +1,50 @@ +class AdminsTest < 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 + + # Called after every test method runs. Can be used to tear + # down fixture information. + + def teardown + # Do nothing + end + + test 'create an admin' do + + post '/api/admins', + { + admin: { + username: 'glepower', + email: 'gerard.lepower@admins.net', + profile_attributes: { + first_name: 'Gérard', + last_name: 'Lepower', + gender: true, + birthday: '1999-09-19', + phone: '0547124852', + address_attributes: { + address: '6 Avenue Henri de Bournazel, 19000 Tulle' + } + } + } + }.to_json, + default_headers + + # Check response format & status + assert_equal 201, response.status, response.body + assert_equal Mime::JSON, response.content_type + + # Check the correct admin was created + admin = json_response(response.body) + user = User.where(id: admin[:admin][:id]).first + assert_not_nil user, 'admin was not created in database' + + # Check he's got the admin role + assert user.has_role?(:admin), 'admin does not have the admin role' + end +end \ No newline at end of file