diff --git a/app/assets/javascripts/discourse/tests/unit/services/store-test.js b/app/assets/javascripts/discourse/tests/unit/services/store-test.js index 33129858c94..9ff3d01bf26 100644 --- a/app/assets/javascripts/discourse/tests/unit/services/store-test.js +++ b/app/assets/javascripts/discourse/tests/unit/services/store-test.js @@ -10,17 +10,17 @@ module("Unit | Service | store", function (hooks) { const store = getOwner(this).lookup("service:store"); const widget = store.createRecord("widget", { id: 111, name: "hello" }); - assert.ok(!widget.get("isNew"), "it is not a new record"); - assert.strictEqual(widget.get("name"), "hello"); - assert.strictEqual(widget.get("id"), 111); + assert.false(widget.isNew, "it is not a new record"); + assert.strictEqual(widget.name, "hello"); + assert.strictEqual(widget.id, 111); }); test("createRecord without an `id`", function (assert) { const store = getOwner(this).lookup("service:store"); const widget = store.createRecord("widget", { name: "hello" }); - assert.ok(widget.get("isNew"), "it is a new record"); - assert.ok(!widget.get("id"), "there is no id"); + assert.true(widget.isNew, "it is a new record"); + assert.strictEqual(widget.id, undefined, "there is no id"); }); test("createRecord doesn't modify the input `id` field", function (assert) { @@ -39,8 +39,8 @@ module("Unit | Service | store", function (hooks) { const store = getOwner(this).lookup("service:store"); const widget = store.createRecord("widget"); - assert.ok(!widget.get("id"), "there is no id"); - assert.ok(widget.get("isNew"), "it is a new record"); + assert.strictEqual(widget.id, undefined, "there is no id"); + assert.true(widget.isNew, "it is a new record"); }); test("createRecord with a record as attributes returns that record from the map", function (assert) { @@ -55,11 +55,11 @@ module("Unit | Service | store", function (hooks) { const store = getOwner(this).lookup("service:store"); const widget = await store.find("widget", 123); - assert.strictEqual(widget.get("name"), "Trout Lure"); - assert.strictEqual(widget.get("id"), 123); - assert.ok(!widget.get("isNew"), "found records are not new"); + assert.strictEqual(widget.name, "Trout Lure"); + assert.strictEqual(widget.id, 123); + assert.false(widget.isNew, "found records are not new"); assert.strictEqual( - widget.get("extras.hello"), + widget.extras.hello, "world", "extra attributes are set" ); @@ -68,7 +68,7 @@ module("Unit | Service | store", function (hooks) { const widget2 = await store.find("widget", 123); assert.strictEqual(widget, widget2); assert.strictEqual( - widget.get("extras.hello"), + widget.extras.hello, "world", "extra attributes are set" ); @@ -77,24 +77,25 @@ module("Unit | Service | store", function (hooks) { test("find with object id", async function (assert) { const store = getOwner(this).lookup("service:store"); const widget = await store.find("widget", { id: 123 }); - assert.strictEqual(widget.get("firstObject.name"), "Trout Lure"); + assert.strictEqual(widget.firstObject.name, "Trout Lure"); }); test("find with query param", async function (assert) { const store = getOwner(this).lookup("service:store"); const widget = await store.find("widget", { name: "Trout Lure" }); - assert.strictEqual(widget.get("firstObject.id"), 123); + assert.strictEqual(widget.firstObject.id, 123); }); test("findStale with no stale results", async function (assert) { const store = getOwner(this).lookup("service:store"); const stale = store.findStale("widget", { name: "Trout Lure" }); - assert.ok(!stale.hasResults, "there are no stale results"); - assert.ok(!stale.results, "results are present"); + assert.false(stale.hasResults, "there are no stale results"); + assert.strictEqual(stale.results, undefined, "results are not present"); + const widget = await stale.refresh(); assert.strictEqual( - widget.get("firstObject.id"), + widget.firstObject.id, 123, "a `refresh()` method provides results for stale" ); @@ -129,49 +130,52 @@ module("Unit | Service | store", function (hooks) { test("update", async function (assert) { const store = getOwner(this).lookup("service:store"); const result = await store.update("widget", 123, { name: "hello" }); - assert.ok(result); + assert.strictEqual(result.payload.name, "hello"); }); test("update with a multi world name", async function (assert) { const store = getOwner(this).lookup("service:store"); const result = await store.update("cool-thing", 123, { name: "hello" }); - assert.ok(result); assert.strictEqual(result.payload.name, "hello"); }); test("findAll", async function (assert) { const store = getOwner(this).lookup("service:store"); const result = await store.findAll("widget"); - assert.strictEqual(result.get("length"), 2); + assert.strictEqual(result.length, 2); const widget = result.findBy("id", 124); - assert.ok(!widget.get("isNew"), "found records are not new"); - assert.strictEqual(widget.get("name"), "Evil Repellant"); + assert.false(widget.isNew, "found records are not new"); + assert.strictEqual(widget.name, "Evil Repellant"); }); test("destroyRecord", async function (assert) { const store = getOwner(this).lookup("service:store"); const widget = await store.find("widget", 123); - assert.ok(await store.destroyRecord("widget", widget)); + const result = await store.destroyRecord("widget", widget); + assert.deepEqual(result, { success: true }); }); test("destroyRecord when new", async function (assert) { const store = getOwner(this).lookup("service:store"); const widget = store.createRecord("widget", { name: "hello" }); - assert.ok(await store.destroyRecord("widget", widget)); + assert.true(await store.destroyRecord("widget", widget)); }); test("find embedded", async function (assert) { const store = getOwner(this).lookup("service:store"); const fruit = await store.find("fruit", 1); - assert.ok(fruit.get("farmer"), "it has the embedded object"); - const fruitCols = fruit.get("colors"); - assert.strictEqual(fruitCols.length, 2); - assert.strictEqual(fruitCols[0].get("id"), 1); - assert.strictEqual(fruitCols[1].get("id"), 2); + assert.propContains( + fruit.farmer, + { id: 1, name: "Old MacDonald" }, + "it has the embedded object" + ); + assert.strictEqual(fruit.colors.length, 2); + assert.strictEqual(fruit.colors[0].id, 1); + assert.strictEqual(fruit.colors[1].id, 2); }); test("embedded records can be cleared", async function (assert) { @@ -180,14 +184,14 @@ module("Unit | Service | store", function (hooks) { fruit.set("farmer", { dummy: "object" }); fruit = await store.find("fruit", 4); - assert.ok(!fruit.get("farmer")); + assert.strictEqual(fruit.farmer, null); }); test("meta types", async function (assert) { const store = getOwner(this).lookup("service:store"); const barn = await store.find("barn", 1); assert.strictEqual( - barn.get("owner.name"), + barn.owner.name, "Old MacDonald", "it has the embedded farmer" ); @@ -196,24 +200,24 @@ module("Unit | Service | store", function (hooks) { test("findAll embedded", async function (assert) { const store = getOwner(this).lookup("service:store"); const fruits = await store.findAll("fruit"); - assert.strictEqual(fruits.objectAt(0).get("farmer.name"), "Old MacDonald"); + assert.strictEqual(fruits.objectAt(0).farmer.name, "Old MacDonald"); assert.strictEqual( - fruits.objectAt(0).get("farmer"), - fruits.objectAt(1).get("farmer"), + fruits.objectAt(0).farmer, + fruits.objectAt(1).farmer, "points at the same object" ); assert.strictEqual( - fruits.get("extras.hello"), + fruits.extras.hello, "world", "it can supply extra information" ); - const fruitCols = fruits.objectAt(0).get("colors"); + const fruitCols = fruits.objectAt(0).colors; assert.strictEqual(fruitCols.length, 2); - assert.strictEqual(fruitCols[0].get("id"), 1); - assert.strictEqual(fruitCols[1].get("id"), 2); + assert.strictEqual(fruitCols[0].id, 1); + assert.strictEqual(fruitCols[1].id, 2); - assert.strictEqual(fruits.objectAt(2).get("farmer.name"), "Luke Skywalker"); + assert.strictEqual(fruits.objectAt(2).farmer.name, "Luke Skywalker"); }); test("custom primaryKey", async function (assert) {