Skip to content

Commit

Permalink
fix(mutators): fix mutator frost behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Lauer authored and Jake Lauer committed Aug 1, 2024
1 parent ef2d1f3 commit d66960b
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 7 deletions.
256 changes: 256 additions & 0 deletions src/_test/bad-cards.test-dep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
import structuredClone from "@ungap/structured-clone";

const MockGameItem = {
"gameType": "AllBadCards",
"dateCreated": "2024-06-29T03:45:12.336Z",
"dateUpdated": "2024-06-29T03:45:17.396Z",
"blackCard": {
"cardIndex": 697,
"cardRating": 3,
"packId": "002_base",
},
"chooserGuid": "tx2N9Keo68UR6woJz0689",
"stack": "Error\n at _GameManager.updateGame (/var/app/current/output/server/server.js:651186:27)\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)\n at async _GameManager.startGame (/var/app/current/output/server/server.js:651532:9)\n at async /var/app/current/output/server/server.js:647409:13",
"id": "disfigured-ant-3998",
"kickedPlayers": {},
"lastWinner": null,
"ownerGuid": "tx2N9Keo68UR6woJz0689",
"pendingPlayers": {},
"playerOrder": [],
"players": {
"tx2N9Keo68UR6woJz0689": {
"userId": null,
"lastUpdated": 1719632712336,
"isSubscriber": false,
"hideGameAds": false,
"levels": [],
"guid": "tx2N9Keo68UR6woJz0689",
"whiteCards": [
{
"cardIndex": 2447,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 2265,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 966,
"cardRating": 1,
"packId": "002_base",
},
{
"cardIndex": 1162,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 275,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 196,
"cardRating": 2,
"packId": "002_base",
},
],
"nickname": "asdf",
"wins": 0,
"isSpectating": false,
"isRandom": false,
"isIdle": false,
"kickedForTimeout": false,
"emailValidated": false,
"isApproved": null,
"hidden": false,
},
"sLtsDz6WsZqVmtJQFVm6x": {
"userId": null,
"lastUpdated": 1719632715139,
"isSubscriber": false,
"hideGameAds": false,
"levels": [],
"guid": "sLtsDz6WsZqVmtJQFVm6x",
"whiteCards": [
{
"cardIndex": 278,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 583,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 2258,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 1455,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 305,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 1608,
"cardRating": 3,
"packId": "002_base",
},
],
"nickname": "Emo%20Donkeyby",
"wins": 0,
"isSpectating": false,
"isRandom": true,
"isIdle": false,
"kickedForTimeout": false,
"emailValidated": false,
"isApproved": true,
"hidden": false,
},
"Env5KESYkphdBtlkeHA4z": {
"userId": null,
"lastUpdated": 1719632715821,
"isSubscriber": false,
"hideGameAds": false,
"levels": [],
"guid": "Env5KESYkphdBtlkeHA4z",
"whiteCards": [
{
"cardIndex": 2452,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 2214,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 2727,
"cardRating": 1,
"packId": "002_base",
},
{
"cardIndex": 2195,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 1736,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 976,
"cardRating": 1,
"packId": "002_base",
},
],
"nickname": "Fool%20FitzFarty",
"wins": 0,
"isSpectating": false,
"isRandom": true,
"isIdle": false,
"kickedForTimeout": false,
"emailValidated": false,
"isApproved": true,
"hidden": false,
},
"XP30rXfLBtj6KjzCVgVpd": {
"userId": null,
"lastUpdated": 1719632716453,
"isSubscriber": false,
"hideGameAds": false,
"levels": [],
"guid": "XP30rXfLBtj6KjzCVgVpd",
"whiteCards": [
{
"cardIndex": 2282,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 1739,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 1405,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 189,
"cardRating": 2,
"packId": "002_base",
},
{
"cardIndex": 1463,
"cardRating": 3,
"packId": "002_base",
},
{
"cardIndex": 957,
"cardRating": 1,
"packId": "002_base",
},
],
"nickname": "Stupid%20Donkeyerino",
"wins": 0,
"isSpectating": false,
"isRandom": true,
"isIdle": false,
"kickedForTimeout": false,
"emailValidated": false,
"isApproved": true,
"hidden": false,
},
},
"revealIndex": -1,
"roundCards": {},
"roundIndex": 0,
"roundStarted": false,
"settings": {
"ratings": [
1,
3,
],
"public": true,
"hideDuringReveal": false,
"skipReveal": false,
"suggestedRoundsToWin": 12,
"playerLimit": 12,
"inviteLink": null,
"includedPacks": [
"002_base",
],
"includedCustomPackIds": [],
"winnerBecomesCzar": false,
"allowCustoms": false,
"roundTimeoutSeconds": 60,
"requireJoinApproval": false,
"ownerIsPermaczar": false,
"voteTimeoutSeconds": 60,
},
"serverSettings": {
"isVotingMode": false,
},
"spectators": {},
"updateFrom": "tx2N9Keo68UR6woJz0689",
"started": true,
"buildVersion": 1717803449479,
};

export const GetMockGameItem = () =>
{
return structuredClone(MockGameItem);
};
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ export class MutatorSetBuilder<

protected augmentData(data: TData)
{
const dataInput = this.sandboxableOptions?.frost?.manual
? this.data
: frost(this.data);

const sb = sandbox(dataInput, this.sandboxableOptions?.sandbox);
const sb = sandbox(this.data, this.sandboxableOptions?.sandbox);
sb[this.paramNoun] = data;
return sb;
}
Expand Down
29 changes: 27 additions & 2 deletions src/lib/Evolvers/_test/Evolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,28 @@ describe("Evolvers", () =>
sandbox: {
mode: "modify",
},
frost: {
manual: false,
})
.toEvolve<AnotherTestData>()
.withMutators({
rename: ({ input }) => ({
name: `New ${input.name}`,
}),
});

const original: AnotherTestData = {
name: "Jake",
};
const evolved = stringEvolver.evolve(original).via.rename().end();
const cemented = cement(evolved);
expect(cemented).to.deep.equal(original, "The evolved data should hold the same data as the original");
expect(cemented).not.to.equal(original, "The evolved data should not be the same object");
});

it("should allow multiple evolutions with auto-frost", () =>
{
const stringEvolver = Evolver.create("string", {
sandbox: {
mode: "modify",
},
})
.toEvolve<AnotherTestData>()
Expand All @@ -225,9 +245,14 @@ describe("Evolvers", () =>
name: "Jake",
};
const evolved = stringEvolver.evolve(original).via.rename().end();
const evolved2 = stringEvolver.evolve(evolved).via.rename().end();
const cemented = cement(evolved);
const cemented2 = cement(evolved2);
expect(cemented2.name).to.equal("New New Jake");
expect(cemented).to.deep.equal(original, "The evolved data should hold the same data as the original");
expect(cemented).not.to.equal(original, "The evolved data should not be the same object");
expect(cemented2).to.deep.equal(original, "The evolved data should hold the same data as the original");
expect(cemented2).not.to.equal(original, "The evolved data should not be the same object");
});
});

Expand Down

0 comments on commit d66960b

Please sign in to comment.