Skip to content

Commit

Permalink
[BUGFIX] recharge les places lorsque le prescrit change d'organisation (
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored May 27, 2024
2 parents 6093c06 + 41ecd3e commit ca51f41
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion orga/app/components/layout/topbar.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="topbar">
<Layout::OrganizationPlacesOrCreditInfo @placesCount={{@placesCount}} />
<Layout::UserLoggedMenu class="topbar__user-logged-menu" />
<Layout::UserLoggedMenu class="topbar__user-logged-menu" @reloadPlaceStatistics={{@reloadPlaceStatistics}} />
</div>
1 change: 1 addition & 0 deletions orga/app/components/layout/user-logged-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class UserLoggedMenu extends Component {
this.router.replaceWith('authenticated', { queryParams });

await this.currentUser.load();
this.args.reloadPlaceStatistics();

this.closeMenu();
}
Expand Down
13 changes: 13 additions & 0 deletions orga/app/controllers/authenticated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { service } from '@ember/service';

export default class AuthenticatedController extends Controller {
@service currentUser;
@service store;

@action
reloadPlaceStatistics() {
this.send('refreshModel');
}
}
6 changes: 6 additions & 0 deletions orga/app/routes/authenticated.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { action } from '@ember/object';
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import get from 'lodash/get';
Expand Down Expand Up @@ -28,4 +29,9 @@ export default class AuthenticatedRoute extends Route {
});
} else return null;
}

@action
refreshModel() {
this.refresh();
}
}
4 changes: 3 additions & 1 deletion orga/app/services/current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default class CurrentUserService extends Service {
async load() {
if (this.session.isAuthenticated) {
try {
this.prescriber = await this.store.findRecord('prescriber', this.session.data.authenticated.user_id);
this.prescriber = await this.store.findRecord('prescriber', this.session.data.authenticated.user_id, {
reload: true,
});
this.memberships = await this.prescriber.memberships;
const userOrgaSettings = await this.prescriber.userOrgaSettings;
const membership = await this._getMembershipByUserOrgaSettings(this.memberships.slice(), userOrgaSettings);
Expand Down
2 changes: 1 addition & 1 deletion orga/app/templates/authenticated.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div class="main-content">
<header>
<Layout::Topbar @placesCount={{@model.available}} />
<Layout::Topbar @placesCount={{@model.available}} @reloadPlaceStatistics={{this.reloadPlaceStatistics}} />
</header>

<main class="main-content__body page">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ module('Integration | Component | Layout::UserLoggedMenu', function (hooks) {

test('should redirect to authenticated route before reload the current user', async function (assert) {
const replaceWithStub = sinon.stub();
const reloadPlaceStatistics = sinon.stub();

class RouterStub extends Service {
replaceWith = replaceWithStub;
currentRoute = { queryParams: [] };
Expand All @@ -105,15 +107,15 @@ module('Integration | Component | Layout::UserLoggedMenu', function (hooks) {
return { save() {} };
}
}

this.set('reloadPlaceStatistics', reloadPlaceStatistics);
this.owner.register('service:router', RouterStub);
this.owner.register('service:store', StoreStub);

const screen = await render(hbs`<Layout::UserLoggedMenu />`);
const screen = await render(hbs`<Layout::UserLoggedMenu @reloadPlaceStatistics={{this.reloadPlaceStatistics}} />`);
await clickByName('Ouvrir le menu utilisateur');
await click(screen.getByRole('button', { name: `${organization2.name} (${organization2.externalId})` }));

sinon.assert.callOrder(replaceWithStub, loadStub);
assert.ok(true);
assert.ok(reloadPlaceStatistics.calledOnce);
});
});
18 changes: 18 additions & 0 deletions orga/tests/unit/controllers/authenticated_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';
import sinon from 'sinon';

module('Unit | Controller | authenticated', function (hooks) {
setupTest(hooks);

test('should call send method', async function (assert) {
// given
const controller = this.owner.lookup('controller:authenticated');
controller.send = sinon.stub();

// when
controller.reloadPlaceStatistics();
// then
assert.true(controller.send.calledWithExactly('refreshModel'));
});
});
14 changes: 14 additions & 0 deletions orga/tests/unit/routes/authenticated_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,18 @@ module('Unit | Route | authenticated', function (hooks) {
assert.notOk(queryRecordStub.calledWithExactly('organization-place-statistic', { organizationId }));
});
});

module('refreshModel', function () {
test('should call refresh', async function (assert) {
// given
const route = this.owner.lookup('route:authenticated');
route.refresh = sinon.stub();

// when
route.refreshModel();

// then
assert.ok(route.refresh.called);
});
});
});

0 comments on commit ca51f41

Please sign in to comment.