Skip to content

Commit

Permalink
feat(admin): add detachTargetProfile in adapter
Browse files Browse the repository at this point in the history
of training

Co-authored-by: Clément Latzarus <[email protected]>
Co-authored-by: Eric Lim <[email protected]>
  • Loading branch information
3 people committed Feb 14, 2025
1 parent ddada16 commit e10f890
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions admin/app/adapters/training.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ export default class TrainingAdapter extends ApplicationAdapter {
const url = `${this.host}/${this.namespace}/trainings/${trainingId}/attach-target-profiles`;
return this.ajax(url, 'POST', { data: payload });
}

async detachTargetProfile(options) {
const { targetProfileId, trainingId } = options;

const url = `${this.host}/${this.namespace}/trainings/${trainingId}/target-profiles/${targetProfileId}`;
return this.ajax(url, 'DELETE');
}
}
16 changes: 16 additions & 0 deletions admin/tests/unit/adapters/training-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,20 @@ module('Unit | Adapter | Training ', function (hooks) {
assert.ok(true);
});
});
module('#detachTargetProfile', function () {
test('should trigger an ajax call with the right url, method and payload', async function (assert) {
// given
sinon.stub(adapter, 'ajax').resolves();
const trainingId = 1;
const targetProfileId = 2;
const expectedUrl = `http://localhost:3000/api/admin/trainings/${trainingId}/target-profiles/${targetProfileId}`;

// when
await adapter.detachTargetProfile({ trainingId, targetProfileId });

// then
sinon.assert.calledWith(adapter.ajax, expectedUrl, 'DELETE');
assert.ok(true);
});
});
});

0 comments on commit e10f890

Please sign in to comment.