Skip to content

Commit 328d467

Browse files
authored
Merge pull request #3669 from openstax/fix/refund
fix refund api request
2 parents 7e78636 + c3d9d1a commit 328d467

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

shared/src/model/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class ModelApi {
3030
}
3131
return null
3232
},
33-
})) //observable.map<string, ApiError>({}, { deep: false })
33+
}))
3434

3535
@readonly requestCounts = observable({
3636
read: 0,

tutor/specs/models/purchases/purchase.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Purchase, Course } from '../../../src/models'
2-
import { Factory, hydrateModel } from '../../helpers'
2+
import { Factory, hydrateModel, ApiMock } from '../../helpers'
33

44
describe('Purchase Model', () => {
55
let course!:Course
@@ -16,8 +16,11 @@ describe('Purchase Model', () => {
1616
expect(purchase.course).toBe(course)
1717
});
1818

19-
test('#onRefunded', () => {
20-
purchase.onRefunded();
19+
test('#onRefunded', async () => {
20+
ApiMock.mock({
21+
[`purchases/${purchase.product_instance_uuid}/refund`]: { ok: true },
22+
})
23+
await purchase.refund();
2124
expect(course.userStudentRecord!.is_paid).toBe(false);
2225
expect(course.userStudentRecord!.prompt_student_to_pay).toBe(true);
2326
});

tutor/src/models/purchases/purchase.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { pick, extend } from 'lodash';
2-
import { BaseModel, field, model, computed, modelize, NEW_ID } from 'shared/model';
2+
import { BaseModel, field, model, computed, action, modelize, NEW_ID } from 'shared/model';
33
import Time from 'shared/model/time';
44
import S from '../../helpers/string';
55
import { currentCourses } from '../../../src/models'
6+
import urlFor from '../../api'
67

78
class Product extends BaseModel {
89
@field uuid = '';
@@ -67,15 +68,16 @@ export class Purchase extends BaseModel {
6768
return amount;
6869
}
6970

70-
refund() {
71-
return { item_uuid: this.product_instance_uuid, refund_survey: this.refund_survey };
71+
@action async refund() {
72+
await this.api.request(urlFor('requestRefund', { itemUUID: this.product_instance_uuid }), {
73+
data: { refund_survey: this.refund_survey },
74+
})
75+
this.onRefunded()
7276
}
7377

74-
onRefunded() {
78+
@action onRefunded() {
7579
this.is_refunded = true;
76-
if (this.course) {
77-
this.course.userStudentRecord?.markRefunded();
78-
}
80+
this.course?.userStudentRecord?.markRefunded();
7981
}
8082

8183
}

0 commit comments

Comments
 (0)