|
1 | 1 | import test from "node:test"; |
2 | 2 | import assert from "node:assert/strict"; |
3 | 3 |
|
4 | | -import {buildMarketplaceMessageEventsPayload, buildMarketplaceMessagingPayload} from "../src/services/minecraft.service.js"; |
| 4 | +import jwtLib from "jsonwebtoken"; |
| 5 | +import {buildMarketplaceMessageEventsPayload, buildMarketplaceMessagingPayload, extractReceiptEntitlements} from "../src/services/minecraft.service.js"; |
5 | 6 |
|
6 | 7 | test("buildMarketplaceMessagingPayload uses defaults", () => { |
7 | 8 | const {payload, sessionId} = buildMarketplaceMessagingPayload({}); |
@@ -72,3 +73,29 @@ test("buildMarketplaceMessageEventsPayload builds multiple events", () => { |
72 | 73 | eventDateTime: "2026-01-21T10:14:44.051Z" |
73 | 74 | }]); |
74 | 75 | }); |
| 76 | + |
| 77 | +test("extractReceiptEntitlements reads jwt receipt entitlements", () => { |
| 78 | + const receiptPayload = {Receipt: {Entitlements: [{CreatorId: "creator-1"}]}}; |
| 79 | + const token = jwtLib.sign(receiptPayload, "secret"); |
| 80 | + const ents = extractReceiptEntitlements(token); |
| 81 | + assert.deepEqual(ents, receiptPayload.Receipt.Entitlements); |
| 82 | +}); |
| 83 | + |
| 84 | +test("extractReceiptEntitlements reads json receipt entitlements", () => { |
| 85 | + const receiptPayload = {Receipt: {Entitlements: [{CreatorId: "creator-2"}]}}; |
| 86 | + const ents = extractReceiptEntitlements(JSON.stringify(receiptPayload)); |
| 87 | + assert.deepEqual(ents, receiptPayload.Receipt.Entitlements); |
| 88 | +}); |
| 89 | + |
| 90 | +test("extractReceiptEntitlements reads base64 receipt entitlements", () => { |
| 91 | + const receiptPayload = {Receipt: {Entitlements: [{CreatorId: "creator-3"}]}}; |
| 92 | + const encoded = Buffer.from(JSON.stringify(receiptPayload), "utf8").toString("base64"); |
| 93 | + const ents = extractReceiptEntitlements(encoded); |
| 94 | + assert.deepEqual(ents, receiptPayload.Receipt.Entitlements); |
| 95 | +}); |
| 96 | + |
| 97 | +test("extractReceiptEntitlements reads object receipt entitlements", () => { |
| 98 | + const receiptPayload = {Receipt: {Entitlements: [{CreatorId: "creator-4"}]}}; |
| 99 | + const ents = extractReceiptEntitlements(receiptPayload); |
| 100 | + assert.deepEqual(ents, receiptPayload.Receipt.Entitlements); |
| 101 | +}); |
0 commit comments