Skip to content

Commit f28bc24

Browse files
committedMar 28, 2025
feat(api): create adapter to retrieve attestation detail
1 parent e6d9152 commit f28bc24

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
 

Diff for: ‎mon-pix/app/adapters/attestation-detail.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { service } from '@ember/service';
2+
3+
import ApplicationAdapter from './application';
4+
5+
export default class AttestationDetail extends ApplicationAdapter {
6+
@service currentUser;
7+
8+
namespace = `api/users/${this.currentUser.user.id}`;
9+
}

Diff for: ‎mon-pix/app/models/attestation-detail.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Model, { attr } from '@ember-data/model';
2+
3+
export default class AttestationDetail extends Model {
4+
@attr('string') type;
5+
@attr('date') obtainedAt;
6+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Service from '@ember/service';
2+
import { setupTest } from 'ember-qunit';
3+
import { module, test } from 'qunit';
4+
import sinon from 'sinon';
5+
6+
module('Unit | Adapter | attestation-detail', function (hooks) {
7+
setupTest(hooks);
8+
9+
module('#findRecord', function () {
10+
test('should send a GET request to user attestation-detail endpoint', async function (assert) {
11+
// given
12+
class CurrentUserStub extends Service {
13+
user = {
14+
id: '1234',
15+
};
16+
}
17+
this.owner.register('service:current-user', CurrentUserStub);
18+
const adapter = this.owner.lookup('adapter:attestation-detail');
19+
sinon.stub(adapter, 'ajax');
20+
21+
// when
22+
await adapter.findRecord(null, 'attestation-detail');
23+
24+
// then
25+
const expectedUrl = 'http://localhost:3000/api/users/1234/attestation-details';
26+
sinon.assert.calledWith(adapter.ajax, expectedUrl, 'GET');
27+
assert.ok(adapter); /* required because QUnit wants at least one expect (and does not accept Sinon's one) */
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)