Skip to content

Commit

Permalink
Merge pull request #3669 from openstax/fix/refund
Browse files Browse the repository at this point in the history
fix refund api request
  • Loading branch information
nathanstitt authored Jun 29, 2021
2 parents 7e78636 + c3d9d1a commit 328d467
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion shared/src/model/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ModelApi {
}
return null
},
})) //observable.map<string, ApiError>({}, { deep: false })
}))

@readonly requestCounts = observable({
read: 0,
Expand Down
9 changes: 6 additions & 3 deletions tutor/specs/models/purchases/purchase.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Purchase, Course } from '../../../src/models'
import { Factory, hydrateModel } from '../../helpers'
import { Factory, hydrateModel, ApiMock } from '../../helpers'

describe('Purchase Model', () => {
let course!:Course
Expand All @@ -16,8 +16,11 @@ describe('Purchase Model', () => {
expect(purchase.course).toBe(course)
});

test('#onRefunded', () => {
purchase.onRefunded();
test('#onRefunded', async () => {
ApiMock.mock({
[`purchases/${purchase.product_instance_uuid}/refund`]: { ok: true },
})
await purchase.refund();
expect(course.userStudentRecord!.is_paid).toBe(false);
expect(course.userStudentRecord!.prompt_student_to_pay).toBe(true);
});
Expand Down
16 changes: 9 additions & 7 deletions tutor/src/models/purchases/purchase.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { pick, extend } from 'lodash';
import { BaseModel, field, model, computed, modelize, NEW_ID } from 'shared/model';
import { BaseModel, field, model, computed, action, modelize, NEW_ID } from 'shared/model';
import Time from 'shared/model/time';
import S from '../../helpers/string';
import { currentCourses } from '../../../src/models'
import urlFor from '../../api'

class Product extends BaseModel {
@field uuid = '';
Expand Down Expand Up @@ -67,15 +68,16 @@ export class Purchase extends BaseModel {
return amount;
}

refund() {
return { item_uuid: this.product_instance_uuid, refund_survey: this.refund_survey };
@action async refund() {
await this.api.request(urlFor('requestRefund', { itemUUID: this.product_instance_uuid }), {
data: { refund_survey: this.refund_survey },
})
this.onRefunded()
}

onRefunded() {
@action onRefunded() {
this.is_refunded = true;
if (this.course) {
this.course.userStudentRecord?.markRefunded();
}
this.course?.userStudentRecord?.markRefunded();
}

}

0 comments on commit 328d467

Please sign in to comment.