From 28b70cda6b248914cf50322e5924235e6242c0f4 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Thu, 16 Nov 2023 11:00:58 -0800 Subject: [PATCH 01/17] Add eslintrc for tests/builders --- config/eslint/diagnostic.cjs | 24 +++++ pnpm-lock.yaml | 101 +++++++++++++----- tests/builders/.eslintrc.cjs | 39 +++++++ tests/builders/app/services/store.ts | 5 +- tests/builders/config/environment.js | 2 +- tests/builders/ember-cli-build.js | 4 +- tests/builders/package.json | 2 + .../tests/integration/create-record-test.ts | 22 ++-- .../tests/integration/delete-record-test.ts | 19 ++-- .../tests/integration/update-record-test.ts | 26 +++-- .../tests/unit/active-record-builder-test.ts | 11 +- .../tests/unit/build-base-url-test.ts | 3 +- .../tests/unit/build-query-params-test.ts | 3 +- .../builders/tests/unit/filter-empty-test.ts | 3 +- .../tests/unit/json-api-builder-test.ts | 11 +- .../tests/unit/parse-cache-control-test.ts | 3 +- .../builders/tests/unit/rest-builder-test.ts | 11 +- tests/builders/tsconfig.json | 2 +- 18 files changed, 205 insertions(+), 86 deletions(-) create mode 100644 config/eslint/diagnostic.cjs create mode 100644 tests/builders/.eslintrc.cjs diff --git a/config/eslint/diagnostic.cjs b/config/eslint/diagnostic.cjs new file mode 100644 index 00000000000..65b3bf3517a --- /dev/null +++ b/config/eslint/diagnostic.cjs @@ -0,0 +1,24 @@ +const isolation = require('./isolation.cjs'); + +function defaults(config = {}) { + return { + files: config.files || ['tests/**/*-test.{js,ts}'], + // HACK: diagnostic API significantly overlaps with the qunit API, so we're + // using the qunit plugin to lint diagnostic files. + extends: ['plugin:qunit/recommended'], + rules: Object.assign( + isolation.rules({ + allowedImports: ['@ember/debug', '@ember/test-helpers', ...(config.allowedImports ?? [])], + }), + config?.rules, + { + 'qunit/no-assert-equal': 'off', + 'qunit/no-ok-equality': 'off', + } + ), + }; +} + +module.exports = { + defaults, +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d3f80de96f3..a66117a89a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2365,6 +2365,9 @@ importers: '@warp-drive/diagnostic': specifier: workspace:5.5.0-alpha.11 version: file:packages/diagnostic(@ember/test-helpers@3.2.0)(@embroider/addon-shim@1.8.7)(ember-cli-test-loader@3.1.0) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-auto-import: specifier: ^2.6.3 version: 2.6.3(webpack@5.89.0) @@ -3391,13 +3394,13 @@ importers: version: 3.2.0(@babel/core@7.23.3)(ember-source@5.4.0)(webpack@5.89.0) '@embroider/compat': specifier: ^3.3.0 - version: 3.3.1(@embroider/core@3.4.1) + version: 3.3.1(@embroider/core@3.4.2) '@embroider/core': specifier: ^3.4.0 - version: 3.4.1 + version: 3.4.2 '@embroider/webpack': specifier: ^3.2.1 - version: 3.2.1(@embroider/core@3.4.1)(webpack@5.89.0) + version: 3.2.1(@embroider/core@3.4.2)(webpack@5.89.0) '@glimmer/component': specifier: ^1.1.2 version: 1.1.2(@babel/core@7.23.3) @@ -3907,13 +3910,13 @@ importers: version: 3.2.0(@babel/core@7.23.3)(ember-source@5.4.0)(webpack@5.89.0) '@embroider/compat': specifier: ^3.3.0 - version: 3.3.1(@embroider/core@3.4.1) + version: 3.3.1(@embroider/core@3.4.2) '@embroider/core': specifier: ^3.4.0 - version: 3.4.1 + version: 3.4.2 '@embroider/webpack': specifier: ^3.2.1 - version: 3.2.1(@embroider/core@3.4.1)(webpack@5.89.0) + version: 3.2.1(@embroider/core@3.4.2)(webpack@5.89.0) '@glimmer/component': specifier: ^1.1.2 version: 1.1.2(@babel/core@7.23.3) @@ -4018,13 +4021,13 @@ importers: version: 3.2.0(@babel/core@7.23.3)(ember-source@5.4.0)(webpack@5.89.0) '@embroider/compat': specifier: ^3.3.0 - version: 3.3.1(@embroider/core@3.4.1) + version: 3.3.1(@embroider/core@3.4.2) '@embroider/core': specifier: ^3.4.0 - version: 3.4.1 + version: 3.4.2 '@embroider/webpack': specifier: ^3.2.1 - version: 3.2.1(@embroider/core@3.4.1)(webpack@5.89.0) + version: 3.2.1(@embroider/core@3.4.2)(webpack@5.89.0) '@glimmer/component': specifier: ^1.1.2 version: 1.1.2(@babel/core@7.23.3) @@ -4413,6 +4416,15 @@ packages: semver: 6.3.1 dev: false + /@babel/generator@7.23.0: + resolution: {integrity: sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/types': 7.23.0 + '@jridgewell/gen-mapping': 0.3.3 + '@jridgewell/trace-mapping': 0.3.20 + jsesc: 2.5.2 + /@babel/generator@7.23.3: resolution: {integrity: sha512-keeZWAV4LU3tW0qRi19HRpabC/ilM0HRBBzf9/k8FFiG4KVpiv0FIy4hHfLfFQZNhziCTPTmd59zoyv6DNISzg==} engines: {node: '>=6.9.0'} @@ -4629,6 +4641,13 @@ packages: chalk: 2.4.2 js-tokens: 4.0.0 + /@babel/parser@7.23.0: + resolution: {integrity: sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==} + engines: {node: '>=6.0.0'} + hasBin: true + dependencies: + '@babel/types': 7.23.0 + /@babel/parser@7.23.3: resolution: {integrity: sha512-uVsWNvlVsIninV2prNz/3lHCb+5CJ+e+IUBfbjToAHODtfGYLfCFuY4AU7TskI+dAKk+njsPiBjq1gKTvZOBaw==} engines: {node: '>=6.0.0'} @@ -6228,6 +6247,23 @@ packages: '@babel/parser': 7.23.3 '@babel/types': 7.23.3 + /@babel/traverse@7.23.2: + resolution: {integrity: sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/code-frame': 7.22.13 + '@babel/generator': 7.23.0 + '@babel/helper-environment-visitor': 7.22.20 + '@babel/helper-function-name': 7.23.0 + '@babel/helper-hoist-variables': 7.22.5 + '@babel/helper-split-export-declaration': 7.22.6 + '@babel/parser': 7.23.0 + '@babel/types': 7.23.0 + debug: 4.3.4(supports-color@8.1.1) + globals: 11.12.0 + transitivePeerDependencies: + - supports-color + /@babel/traverse@7.23.3(supports-color@8.1.1): resolution: {integrity: sha512-+K0yF1/9yR0oHdE0StHuEj3uTPzwwbrLGfNOndVJVV2TqA5+j3oljJUb4nmB954FLGjNem976+B+eDuLIjesiQ==} engines: {node: '>=6.9.0'} @@ -6354,7 +6390,7 @@ packages: engines: {node: 12.* || 14.* || >= 16} hasBin: true dependencies: - '@embroider/core': 3.4.1 + '@embroider/core': 3.4.2 '@rollup/pluginutils': 4.2.1 content-tag: 1.1.2 fs-extra: 10.1.0 @@ -6382,21 +6418,21 @@ packages: transitivePeerDependencies: - supports-color - /@embroider/babel-loader-9@3.1.1(@embroider/core@3.4.1)(supports-color@8.1.1)(webpack@5.89.0): + /@embroider/babel-loader-9@3.1.1(@embroider/core@3.4.2)(supports-color@8.1.1)(webpack@5.89.0): resolution: {integrity: sha512-8mIDRXvwntYIQc2JFVvGXEppHUJRhw+6aEzHtbCZDr4oOKw55IyY+RHzas3JILRq64owLA+Ox0yu6nkwL1ApRQ==} engines: {node: 12.* || 14.* || >= 16} peerDependencies: '@embroider/core': ^3.4.0 dependencies: '@babel/core': 7.23.3(supports-color@8.1.1) - '@embroider/core': 3.4.1 + '@embroider/core': 3.4.2 babel-loader: 9.1.3(@babel/core@7.23.3)(webpack@5.89.0) transitivePeerDependencies: - supports-color - webpack dev: true - /@embroider/compat@3.3.1(@embroider/core@3.4.1): + /@embroider/compat@3.3.1(@embroider/core@3.4.2): resolution: {integrity: sha512-0jG2GzJqfqEvsNQ8MiU6B4INYQ5UN3YDzIYgXBuT7QEVxtoEAV3yCQNtJgi/BnIjFu+i3WYqSDjByfToDlgphg==} engines: {node: 12.* || 14.* || >= 16} hasBin: true @@ -6410,7 +6446,7 @@ packages: '@babel/preset-env': 7.23.3(@babel/core@7.23.3) '@babel/runtime': 7.23.2 '@babel/traverse': 7.23.3(supports-color@8.1.1) - '@embroider/core': 3.4.1 + '@embroider/core': 3.4.2 '@embroider/macros': 1.13.2(@babel/core@7.23.3) '@types/babel__code-frame': 7.0.5 '@types/yargs': 17.0.29 @@ -6453,8 +6489,8 @@ packages: - utf-8-validate dev: true - /@embroider/core@3.4.1: - resolution: {integrity: sha512-zI6ie90S0mXp4zjvhTVxFmBKy0+T0zLqkrOp2vqCjB7zA/sbnivp+N9oqBg6AmRmG08Jw4L/bRx+m4ntHTGvPQ==} + /@embroider/core@3.4.2: + resolution: {integrity: sha512-lHJcUosSgA8v9deZ2a3k/zuQCpu+Rjw1PZ4dOHzdoTN7B9J96IIybw1JVN234sdUJi9VWjpQnvE2uWOD9seRjg==} engines: {node: 12.* || 14.* || >= 16} dependencies: '@babel/core': 7.23.3(supports-color@8.1.1) @@ -6489,7 +6525,7 @@ packages: - utf-8-validate dev: true - /@embroider/hbs-loader@3.0.3(@embroider/core@3.4.1)(webpack@5.89.0): + /@embroider/hbs-loader@3.0.3(@embroider/core@3.4.2)(webpack@5.89.0): resolution: {integrity: sha512-sI2K3/III1WGGxS+aIf8uW5tgcNiE7APNhThn2ZTwqU47fK20Uz8TJZhst0GfNZFsCsmuQMRUikRJvQU8naSWA==} engines: {node: 12.* || 14.* || >= 16} peerDependencies: @@ -6499,7 +6535,7 @@ packages: webpack: optional: true dependencies: - '@embroider/core': 3.4.1 + '@embroider/core': 3.4.2 webpack: 5.89.0 dev: true @@ -6556,7 +6592,7 @@ packages: transitivePeerDependencies: - supports-color - /@embroider/webpack@3.2.1(@embroider/core@3.4.1)(webpack@5.89.0): + /@embroider/webpack@3.2.1(@embroider/core@3.4.2)(webpack@5.89.0): resolution: {integrity: sha512-bTm1CWCK0Jln6XH0rmZv+MrhR3XIpUgsZsN+6KRnP0Yna9YHa1/ix3rBzn3ke/3yapzA5dqdXVjCUN0XDFMp/g==} engines: {node: 12.* || 14.* || >= 16} peerDependencies: @@ -6567,9 +6603,9 @@ packages: optional: true dependencies: '@babel/core': 7.23.3(supports-color@8.1.1) - '@embroider/babel-loader-9': 3.1.1(@embroider/core@3.4.1)(supports-color@8.1.1)(webpack@5.89.0) - '@embroider/core': 3.4.1 - '@embroider/hbs-loader': 3.0.3(@embroider/core@3.4.1)(webpack@5.89.0) + '@embroider/babel-loader-9': 3.1.1(@embroider/core@3.4.2)(supports-color@8.1.1)(webpack@5.89.0) + '@embroider/core': 3.4.2 + '@embroider/hbs-loader': 3.0.3(@embroider/core@3.4.2)(webpack@5.89.0) '@embroider/shared-internals': 2.5.1(supports-color@8.1.1) '@types/supports-color': 8.1.2 assert-never: 1.2.1 @@ -7215,7 +7251,7 @@ packages: '@pnpm/read-project-manifest': 5.0.1 '@pnpm/types': 9.1.0 '@pnpm/util.lex-comparator': 1.0.0 - fast-glob: 3.3.2 + fast-glob: 3.3.1 p-filter: 2.1.0 /@pnpm/fs.hard-link-dir@2.0.1(@pnpm/logger@5.0.0): @@ -11815,8 +11851,8 @@ packages: resolution: {integrity: sha512-89oVHVJwmLDvGvAUWgS87KpBoRhy3aZ6U0Ql6HOmU4TrPkyaa8pM0W81wj9cIwjYprcQtN9EwzZMHnq46+oUyw==} engines: {node: 8.* || 10.* || >= 12} dependencies: - '@babel/parser': 7.23.3 - '@babel/traverse': 7.23.3(supports-color@8.1.1) + '@babel/parser': 7.23.0 + '@babel/traverse': 7.23.2 recast: 0.18.10 transitivePeerDependencies: - supports-color @@ -12614,6 +12650,16 @@ packages: /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} + /fast-glob@3.3.1: + resolution: {integrity: sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==} + engines: {node: '>=8.6.0'} + dependencies: + '@nodelib/fs.stat': 2.0.5 + '@nodelib/fs.walk': 1.2.8 + glob-parent: 5.1.2 + merge2: 1.4.1 + micromatch: 4.0.5 + /fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} @@ -12623,6 +12669,7 @@ packages: glob-parent: 5.1.2 merge2: 1.4.1 micromatch: 4.0.5 + dev: true /fast-json-patch@3.1.1: resolution: {integrity: sha512-vf6IHUX2SBcA+5/+4883dsIjpBTqmfBjmYiWK1savxQmFk4JfBMLa7ynTYOs1Rolp/T1betJxHiGD3g1Mn8lUQ==} @@ -13432,7 +13479,7 @@ packages: '@types/glob': 7.2.0 array-union: 2.1.0 dir-glob: 3.0.1 - fast-glob: 3.3.2 + fast-glob: 3.3.1 glob: 7.2.3 ignore: 5.2.4 merge2: 1.4.1 @@ -13458,7 +13505,7 @@ packages: dependencies: array-union: 2.1.0 dir-glob: 3.0.1 - fast-glob: 3.3.2 + fast-glob: 3.3.1 ignore: 5.2.4 merge2: 1.4.1 slash: 3.0.0 diff --git a/tests/builders/.eslintrc.cjs b/tests/builders/.eslintrc.cjs new file mode 100644 index 00000000000..827dc3d3969 --- /dev/null +++ b/tests/builders/.eslintrc.cjs @@ -0,0 +1,39 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const diagnostic = require('@warp-drive/internal-config/eslint/diagnostic.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config({ + files: ['ember-cli-build.js', 'testem.js'], + }), + node.defaults({ + files: ['./config/environment.js', './config/targets.js'], + }), + typescript.defaults(), + diagnostic.defaults({ + files: ['tests/**/*.{js,ts}'], + }), + ], +}; diff --git a/tests/builders/app/services/store.ts b/tests/builders/app/services/store.ts index f0957be4881..615242ee715 100644 --- a/tests/builders/app/services/store.ts +++ b/tests/builders/app/services/store.ts @@ -1,5 +1,3 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; - import JSONAPICache from '@ember-data/json-api'; import type Model from '@ember-data/model'; import { instantiateRecord, teardownRecord } from '@ember-data/model'; @@ -8,7 +6,8 @@ import RequestManager from '@ember-data/request'; import Fetch from '@ember-data/request/fetch'; import DataStore, { CacheHandler } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; import type { Cache } from '@warp-drive/core-types/cache'; export default class Store extends DataStore { diff --git a/tests/builders/config/environment.js b/tests/builders/config/environment.js index 265be9f8b5e..08309c1f849 100644 --- a/tests/builders/config/environment.js +++ b/tests/builders/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'builders-test-app', environment, rootURL: '/', diff --git a/tests/builders/ember-cli-build.js b/tests/builders/ember-cli-build.js index 36cec92dcc8..6a145f21adb 100644 --- a/tests/builders/ember-cli-build.js +++ b/tests/builders/ember-cli-build.js @@ -1,11 +1,11 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { const compatWith = process.env.EMBER_DATA_FULL_COMPAT ? '99.0' : null; - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { emberData: { compatWith, }, diff --git a/tests/builders/package.json b/tests/builders/package.json index 298d4f89421..3819314f3b8 100644 --- a/tests/builders/package.json +++ b/tests/builders/package.json @@ -16,6 +16,7 @@ "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", "build:production": "pnpm build:tests -e production", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "check:types": "tsc --noEmit", "test": "bun ./diagnostic.js", "test:production": "bun ./diagnostic.js", @@ -99,6 +100,7 @@ "@glimmer/tracking": "^1.1.2", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", "@warp-drive/diagnostic": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", diff --git a/tests/builders/tests/integration/create-record-test.ts b/tests/builders/tests/integration/create-record-test.ts index 7ceab8ca272..f5eb9124200 100644 --- a/tests/builders/tests/integration/create-record-test.ts +++ b/tests/builders/tests/integration/create-record-test.ts @@ -1,6 +1,4 @@ -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import JSONAPICache from '@ember-data/json-api'; import { createRecord } from '@ember-data/json-api/request'; @@ -8,16 +6,18 @@ import Model, { attr, instantiateRecord, teardownRecord } from '@ember-data/mode import { buildSchema, modelFor } from '@ember-data/model/hooks'; import type { RequestContext, StructuredDataDocument } from '@ember-data/request'; import RequestManager from '@ember-data/request'; -import { setBuildURLConfig } from '@ember-data/request-utils'; import type { Future, Handler } from '@ember-data/request/-private/types'; +import { setBuildURLConfig } from '@ember-data/request-utils'; import DataStore, { CacheHandler, recordIdentifierFor } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { ModelSchema } from '@ember-data/store/-types/q/ds-model'; -import { JsonApiError } from '@ember-data/store/-types/q/record-data-json-api'; -import { TestContext } from '@ember/test-helpers'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { JsonApiError } from '@ember-data/store/-types/q/record-data-json-api'; import type { Cache } from '@warp-drive/core-types/cache'; +import type { StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document'; import type { SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class TestStore extends DataStore { constructor(args: unknown) { @@ -76,7 +76,7 @@ module('Integration - createRecord', function (hooks) { override didCommit( committedIdentifier: StableRecordIdentifier, result: StructuredDataDocument - ): SingleResourceDataDocument { + ): SingleResourceDataDocument { assert.step(`didCommit ${committedIdentifier.lid}`); return super.didCommit(committedIdentifier, result); } @@ -87,6 +87,7 @@ module('Integration - createRecord', function (hooks) { } // intercept Handler APIs to ensure they are called as expected + // eslint-disable-next-line prefer-const let response: unknown; const TestHandler: Handler = { request(context: RequestContext): Promise> | Future { @@ -156,7 +157,7 @@ module('Integration - createRecord', function (hooks) { override didCommit( committedIdentifier: StableRecordIdentifier, result: StructuredDataDocument - ): SingleResourceDataDocument { + ): SingleResourceDataDocument { assert.step(`didCommit ${committedIdentifier.lid}`); return super.didCommit(committedIdentifier, result); } @@ -167,6 +168,7 @@ module('Integration - createRecord', function (hooks) { } // intercept Handler APIs to ensure they are called as expected + // eslint-disable-next-line prefer-const let response: unknown; const TestHandler: Handler = { request(context: RequestContext): Promise> | Future { @@ -243,6 +245,8 @@ module('Integration - createRecord', function (hooks) { assert.false(user.isDestroyed, 'The user is not destroyed'); assert.false(user.isSaving, 'The user is no longer saving'); + // TODO: Errors type is missing `get` + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access const nameErrors = user.errors.get('name') as Array<{ attribute: string; message: string; diff --git a/tests/builders/tests/integration/delete-record-test.ts b/tests/builders/tests/integration/delete-record-test.ts index f6b90fc8ac0..998e746d3c4 100644 --- a/tests/builders/tests/integration/delete-record-test.ts +++ b/tests/builders/tests/integration/delete-record-test.ts @@ -1,6 +1,4 @@ -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import JSONAPICache from '@ember-data/json-api'; import { deleteRecord } from '@ember-data/json-api/request'; @@ -8,16 +6,18 @@ import Model, { attr, instantiateRecord, teardownRecord } from '@ember-data/mode import { buildSchema, modelFor } from '@ember-data/model/hooks'; import type { RequestContext, StructuredDataDocument } from '@ember-data/request'; import RequestManager from '@ember-data/request'; -import { setBuildURLConfig } from '@ember-data/request-utils'; import type { Future, Handler } from '@ember-data/request/-private/types'; +import { setBuildURLConfig } from '@ember-data/request-utils'; import DataStore, { CacheHandler, recordIdentifierFor } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { ModelSchema } from '@ember-data/store/-types/q/ds-model'; -import { JsonApiError } from '@ember-data/store/-types/q/record-data-json-api'; -import { TestContext } from '@ember/test-helpers'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { JsonApiError } from '@ember-data/store/-types/q/record-data-json-api'; import type { Cache } from '@warp-drive/core-types/cache'; +import type { StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document'; import type { SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class TestStore extends DataStore { constructor(args: unknown) { @@ -76,7 +76,7 @@ module('Integration - deleteRecord', function (hooks) { override didCommit( committedIdentifier: StableRecordIdentifier, result: StructuredDataDocument - ): SingleResourceDataDocument { + ): SingleResourceDataDocument { assert.step(`didCommit ${committedIdentifier.lid}`); return super.didCommit(committedIdentifier, result); } @@ -87,6 +87,7 @@ module('Integration - deleteRecord', function (hooks) { } // intercept Handler APIs to ensure they are called as expected + // eslint-disable-next-line prefer-const let response: unknown; const TestHandler: Handler = { request(context: RequestContext): Promise> | Future { @@ -172,7 +173,7 @@ module('Integration - deleteRecord', function (hooks) { override didCommit( committedIdentifier: StableRecordIdentifier, result: StructuredDataDocument - ): SingleResourceDataDocument { + ): SingleResourceDataDocument { assert.step(`didCommit ${committedIdentifier.lid}`); return super.didCommit(committedIdentifier, result); } diff --git a/tests/builders/tests/integration/update-record-test.ts b/tests/builders/tests/integration/update-record-test.ts index de2659cbb9a..42ce749ea70 100644 --- a/tests/builders/tests/integration/update-record-test.ts +++ b/tests/builders/tests/integration/update-record-test.ts @@ -1,6 +1,4 @@ -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import JSONAPICache from '@ember-data/json-api'; import { updateRecord } from '@ember-data/json-api/request'; @@ -8,16 +6,18 @@ import Model, { attr, instantiateRecord, teardownRecord } from '@ember-data/mode import { buildSchema, modelFor } from '@ember-data/model/hooks'; import type { RequestContext, StructuredDataDocument } from '@ember-data/request'; import RequestManager from '@ember-data/request'; -import { setBuildURLConfig } from '@ember-data/request-utils'; import type { Future, Handler } from '@ember-data/request/-private/types'; +import { setBuildURLConfig } from '@ember-data/request-utils'; import DataStore, { CacheHandler, recordIdentifierFor } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { ModelSchema } from '@ember-data/store/-types/q/ds-model'; -import { JsonApiError } from '@ember-data/store/-types/q/record-data-json-api'; -import { TestContext } from '@ember/test-helpers'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { JsonApiError } from '@ember-data/store/-types/q/record-data-json-api'; import type { Cache } from '@warp-drive/core-types/cache'; -import { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document'; -import { SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; +import type { StableRecordIdentifier } from '@warp-drive/core-types/identifier'; +import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document'; +import type { SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class TestStore extends DataStore { constructor(args: unknown) { @@ -76,7 +76,7 @@ module('Integration - updateRecord', function (hooks) { override didCommit( committedIdentifier: StableRecordIdentifier, result: StructuredDataDocument - ): SingleResourceDataDocument { + ): SingleResourceDataDocument { assert.step(`didCommit ${committedIdentifier.lid}`); return super.didCommit(committedIdentifier, result); } @@ -87,6 +87,7 @@ module('Integration - updateRecord', function (hooks) { } // intercept Handler APIs to ensure they are called as expected + // eslint-disable-next-line prefer-const let response: unknown; const TestHandler: Handler = { request(context: RequestContext): Promise> | Future { @@ -157,7 +158,7 @@ module('Integration - updateRecord', function (hooks) { override didCommit( committedIdentifier: StableRecordIdentifier, result: StructuredDataDocument - ): SingleResourceDataDocument { + ): SingleResourceDataDocument { assert.step(`didCommit ${committedIdentifier.lid}`); return super.didCommit(committedIdentifier, result); } @@ -168,6 +169,7 @@ module('Integration - updateRecord', function (hooks) { } // intercept Handler APIs to ensure they are called as expected + // eslint-disable-next-line prefer-const let response: unknown; const TestHandler: Handler = { request(context: RequestContext): Promise> | Future { @@ -245,6 +247,8 @@ module('Integration - updateRecord', function (hooks) { assert.false(user.isDestroyed, 'The user is not destroyed'); assert.false(user.isSaving, 'The user is no longer saving'); + // TODO: Errors type is missing `get` + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access const nameErrors = user.errors.get('name') as Array<{ attribute: string; message: string; diff --git a/tests/builders/tests/unit/active-record-builder-test.ts b/tests/builders/tests/unit/active-record-builder-test.ts index 373605c1589..047bc9a0a86 100644 --- a/tests/builders/tests/unit/active-record-builder-test.ts +++ b/tests/builders/tests/unit/active-record-builder-test.ts @@ -1,12 +1,13 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import { createRecord, deleteRecord, findRecord, query, updateRecord } from '@ember-data/active-record/request'; import { setBuildURLConfig } from '@ember-data/request-utils'; -import Store, { recordIdentifierFor } from '@ember-data/store'; -import { TestContext } from '@ember/test-helpers'; +import type Store from '@ember-data/store'; +import { recordIdentifierFor } from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; -import UserSetting from '../../app/models/user-setting'; +import type UserSetting from '../../app/models/user-setting'; import { headersToObject } from '../helpers/utils'; const ACTIVE_RECORD_HEADERS = { accept: 'application/json;charset=utf-8' }; diff --git a/tests/builders/tests/unit/build-base-url-test.ts b/tests/builders/tests/unit/build-base-url-test.ts index c289dee2bb9..bd27f78dd5a 100644 --- a/tests/builders/tests/unit/build-base-url-test.ts +++ b/tests/builders/tests/unit/build-base-url-test.ts @@ -1,7 +1,6 @@ -import { module, test } from '@warp-drive/diagnostic'; - import { buildBaseURL, setBuildURLConfig } from '@ember-data/request-utils'; import { test as debug } from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; +import { module, test } from '@warp-drive/diagnostic'; module('buildBaseURL', function (hooks) { hooks.afterEach(function () { diff --git a/tests/builders/tests/unit/build-query-params-test.ts b/tests/builders/tests/unit/build-query-params-test.ts index 82c1bf078ba..12cf7004ee8 100644 --- a/tests/builders/tests/unit/build-query-params-test.ts +++ b/tests/builders/tests/unit/build-query-params-test.ts @@ -1,6 +1,5 @@ -import { module, test } from '@warp-drive/diagnostic'; - import { buildQueryParams } from '@ember-data/request-utils'; +import { module, test } from '@warp-drive/diagnostic'; module('buildQueryParams', function (hooks) { test('It serializes objects with stable key order', function (assert) { diff --git a/tests/builders/tests/unit/filter-empty-test.ts b/tests/builders/tests/unit/filter-empty-test.ts index 8f4aae4e9b5..fb767a94702 100644 --- a/tests/builders/tests/unit/filter-empty-test.ts +++ b/tests/builders/tests/unit/filter-empty-test.ts @@ -1,6 +1,5 @@ -import { module, test } from '@warp-drive/diagnostic'; - import { filterEmpty } from '@ember-data/request-utils'; +import { module, test } from '@warp-drive/diagnostic'; module('filterEmpty', function () { test('it returns an empty object when given an empty object', function (assert) { diff --git a/tests/builders/tests/unit/json-api-builder-test.ts b/tests/builders/tests/unit/json-api-builder-test.ts index 440a6c8b94d..c145b40199d 100644 --- a/tests/builders/tests/unit/json-api-builder-test.ts +++ b/tests/builders/tests/unit/json-api-builder-test.ts @@ -1,12 +1,13 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import { createRecord, deleteRecord, findRecord, postQuery, query, updateRecord } from '@ember-data/json-api/request'; import { setBuildURLConfig } from '@ember-data/request-utils'; -import Store, { recordIdentifierFor } from '@ember-data/store'; -import { TestContext } from '@ember/test-helpers'; +import type Store from '@ember-data/store'; +import { recordIdentifierFor } from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; -import UserSetting from '../../app/models/user-setting'; +import type UserSetting from '../../app/models/user-setting'; import { headersToObject } from '../helpers/utils'; const JSON_API_HEADERS = { accept: 'application/vnd.api+json' }; diff --git a/tests/builders/tests/unit/parse-cache-control-test.ts b/tests/builders/tests/unit/parse-cache-control-test.ts index ead2c543b15..0f3f5381ecb 100644 --- a/tests/builders/tests/unit/parse-cache-control-test.ts +++ b/tests/builders/tests/unit/parse-cache-control-test.ts @@ -1,7 +1,6 @@ -import { module, test } from '@warp-drive/diagnostic'; - import { parseCacheControl } from '@ember-data/request-utils'; import { test as debug } from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; +import { module, test } from '@warp-drive/diagnostic'; module('parseCacheControl', function (hooks) { test('should parse a single Cache-Control directive', function (assert) { diff --git a/tests/builders/tests/unit/rest-builder-test.ts b/tests/builders/tests/unit/rest-builder-test.ts index 270fe1246b9..9dace1566e4 100644 --- a/tests/builders/tests/unit/rest-builder-test.ts +++ b/tests/builders/tests/unit/rest-builder-test.ts @@ -1,12 +1,13 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import { setBuildURLConfig } from '@ember-data/request-utils'; import { createRecord, deleteRecord, findRecord, query, updateRecord } from '@ember-data/rest/request'; -import Store, { recordIdentifierFor } from '@ember-data/store'; -import { TestContext } from '@ember/test-helpers'; +import type Store from '@ember-data/store'; +import { recordIdentifierFor } from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; -import UserSetting from '../../app/models/user-setting'; +import type UserSetting from '../../app/models/user-setting'; import { headersToObject } from '../helpers/utils'; const REST_HEADERS = { accept: 'application/json;charset=utf-8' }; diff --git a/tests/builders/tsconfig.json b/tests/builders/tsconfig.json index 3a781c7337e..2d3b3fc9b50 100644 --- a/tests/builders/tsconfig.json +++ b/tests/builders/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["app/**/*", "config/**/*", "tests/**/*"], + "include": ["app/**/*", "config/**/*", "tests/**/*", "../../@types/ember-data-qunit-asserts"], "baseUrl": ".", "compilerOptions": { "lib": ["DOM", "ESNext"], From 756b2c4da3519df84bff1950e8894101baf3627d Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Thu, 16 Nov 2023 11:18:42 -0800 Subject: [PATCH 02/17] Add eslintrc for tests/docs --- config/eslint/node.cjs | 1 + pnpm-lock.yaml | 3 +++ tests/docs/.eslintrc.cjs | 40 ++++++++++++++++++++++++++++++++++++++++ tests/docs/index.js | 8 ++++---- tests/docs/package.json | 2 ++ 5 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/docs/.eslintrc.cjs diff --git a/config/eslint/node.cjs b/config/eslint/node.cjs index e61a7df5ec9..813097218bf 100644 --- a/config/eslint/node.cjs +++ b/config/eslint/node.cjs @@ -4,6 +4,7 @@ function defaults(config) { parserOptions: { sourceType: config?.useModules ? 'module' : 'script', ecmaVersion: 2022, + ...(config?.parserOptions ?? {}), }, env: { browser: false, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a66117a89a1..581be229e56 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2464,6 +2464,9 @@ importers: specifier: 0.0.10 version: 0.0.10 devDependencies: + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config qunit: specifier: 2.19.4 version: 2.19.4(patch_hash=h2fz5inojlzu6daraxt5bghsqy) diff --git a/tests/docs/.eslintrc.cjs b/tests/docs/.eslintrc.cjs new file mode 100644 index 00000000000..fb2eec903fd --- /dev/null +++ b/tests/docs/.eslintrc.cjs @@ -0,0 +1,40 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const qunit = require('@warp-drive/internal-config/eslint/qunit.cjs'); + +module.exports = { + ...parser.defaults(), + + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: [], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults({ + files: ['**/*.{js,ts}'], + }), + qunit.defaults({ + files: ['index.{js,ts}'], + rules: { + 'qunit/no-assert-logical-expression': 'off', + 'qunit/no-conditional-assertions': 'off', + }, + }), + ], +}; diff --git a/tests/docs/index.js b/tests/docs/index.js index 09c0b3cc639..a4efc4a902d 100644 --- a/tests/docs/index.js +++ b/tests/docs/index.js @@ -84,7 +84,7 @@ QUnit.module('Docs coverage', function (hooks) { } // docs without a private flag are published as public by default // We error for these - let status = item.access || 'public'; + const status = item.access || 'public'; return `(${status}) ${item.module ? `${item.module} ` : ''}${item.class}#${item.name}`; }) .filter(Boolean) @@ -140,7 +140,7 @@ QUnit.module('Docs coverage', function (hooks) { }); test('No missing classitems', function (assert) { - let missing = setDifference(expectedItems, docsItems); + const missing = setDifference(expectedItems, docsItems); assert.emptySet( missing, 'If you intentionally removed a public API method, please udpate tests/docs/expected.js. Otherwise, documentation is missing, incorrectly formatted, or in a directory that is not watched by yuidoc. All files containing documentation must have a yuidoc class declaration.' @@ -148,7 +148,7 @@ QUnit.module('Docs coverage', function (hooks) { }); test('No extraneous classitems', function (assert) { - let extraneous = setDifference(docsItems, expectedItems); + const extraneous = setDifference(docsItems, expectedItems); assert.emptySet( extraneous, 'If you have added new features, please update tests/docs/expected.js and confirm that any public properties are marked both @public and @static to be included in the Ember API Docs viewer.' @@ -168,7 +168,7 @@ QUnit.module('Docs coverage', function (hooks) { }); function setDifference(setA, setB) { - let difference = new Set(setA); + const difference = new Set(setA); for (var elem of setB) { difference.delete(elem); } diff --git a/tests/docs/package.json b/tests/docs/package.json index c26598e03f7..10bb302062b 100644 --- a/tests/docs/package.json +++ b/tests/docs/package.json @@ -12,9 +12,11 @@ "author": "", "scripts": { "test:docs": "qunit ./index.js", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "_syncPnpm": "bun run sync-dependencies-meta-injected" }, "devDependencies": { + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "qunit": "^2.20.0" }, "engines": { From 2ffb555cadc5ac9fbc13f73522a989683a38048c Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Thu, 16 Nov 2023 15:45:34 -0800 Subject: [PATCH 03/17] Add eslintrc to tests/adapter --- config/eslint/diagnostic.cjs | 1 + config/eslint/qunit.cjs | 1 + pnpm-lock.yaml | 3 + tests/docs/.eslintrc.cjs | 1 - tests/ember-data__adapter/.eslintrc.cjs | 40 +++++ .../ember-data__adapter/app/services/store.ts | 5 +- .../ember-data__adapter/config/environment.js | 2 +- tests/ember-data__adapter/ember-cli-build.js | 2 +- tests/ember-data__adapter/package.json | 2 + .../tests/integration/belongs-to-test.js | 101 ++++++----- .../tests/integration/coalescing-test.js | 123 +++++++------ .../tests/integration/generate-id-test.js | 29 ++-- .../tests/integration/has-many-test.js | 163 +++++++++--------- .../tests/integration/mutations-test.js | 77 ++++----- .../tests/integration/queries-test.js | 51 +++--- .../tests/integration/reload-test.js | 41 +++-- .../ember-data__adapter/tests/test-helper.js | 3 +- 17 files changed, 341 insertions(+), 304 deletions(-) create mode 100644 tests/ember-data__adapter/.eslintrc.cjs diff --git a/config/eslint/diagnostic.cjs b/config/eslint/diagnostic.cjs index 65b3bf3517a..05439b5a761 100644 --- a/config/eslint/diagnostic.cjs +++ b/config/eslint/diagnostic.cjs @@ -13,6 +13,7 @@ function defaults(config = {}) { config?.rules, { 'qunit/no-assert-equal': 'off', + 'qunit/no-conditional-assertions': 'off', 'qunit/no-ok-equality': 'off', } ), diff --git a/config/eslint/qunit.cjs b/config/eslint/qunit.cjs index df4c1aa97bb..a1dd577b34a 100644 --- a/config/eslint/qunit.cjs +++ b/config/eslint/qunit.cjs @@ -16,6 +16,7 @@ function defaults(config = {}) { }), config?.rules, { + 'qunit/no-conditional-assertions': 'off', 'qunit/no-ok-equality': 'off', } ), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 581be229e56..c8e80340f95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2536,6 +2536,9 @@ importers: '@warp-drive/diagnostic': specifier: workspace:5.5.0-alpha.11 version: file:packages/diagnostic(@ember/test-helpers@3.2.0)(@embroider/addon-shim@1.8.7)(ember-cli-test-loader@3.1.0) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-auto-import: specifier: ^2.6.3 version: 2.6.3(webpack@5.89.0) diff --git a/tests/docs/.eslintrc.cjs b/tests/docs/.eslintrc.cjs index fb2eec903fd..b0bcb214e41 100644 --- a/tests/docs/.eslintrc.cjs +++ b/tests/docs/.eslintrc.cjs @@ -33,7 +33,6 @@ module.exports = { files: ['index.{js,ts}'], rules: { 'qunit/no-assert-logical-expression': 'off', - 'qunit/no-conditional-assertions': 'off', }, }), ], diff --git a/tests/ember-data__adapter/.eslintrc.cjs b/tests/ember-data__adapter/.eslintrc.cjs new file mode 100644 index 00000000000..685245dd9cd --- /dev/null +++ b/tests/ember-data__adapter/.eslintrc.cjs @@ -0,0 +1,40 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const diagnostic = require('@warp-drive/internal-config/eslint/diagnostic.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config({ + files: ['ember-cli-build.js', 'testem.js'], + }), + node.defaults({ + files: ['./config/environment.js', './config/targets.js'], + }), + typescript.defaults(), + diagnostic.defaults({ + files: ['tests/**/*.{js,ts}'], + allowedImports: ['@ember/object'], + }), + ], +}; diff --git a/tests/ember-data__adapter/app/services/store.ts b/tests/ember-data__adapter/app/services/store.ts index 33a046b1899..3a52705a78e 100644 --- a/tests/ember-data__adapter/app/services/store.ts +++ b/tests/ember-data__adapter/app/services/store.ts @@ -1,5 +1,3 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; - import JSONAPICache from '@ember-data/json-api'; import { adapterFor, @@ -16,7 +14,8 @@ import RequestManager from '@ember-data/request'; import Fetch from '@ember-data/request/fetch'; import BaseStore, { CacheHandler } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; export default class Store extends BaseStore { constructor(args: unknown) { diff --git a/tests/ember-data__adapter/config/environment.js b/tests/ember-data__adapter/config/environment.js index 427bedd99c4..68a704ce567 100644 --- a/tests/ember-data__adapter/config/environment.js +++ b/tests/ember-data__adapter/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'ember-data__adapter', environment, rootURL: '/', diff --git a/tests/ember-data__adapter/ember-cli-build.js b/tests/ember-data__adapter/ember-cli-build.js index 665f118b239..7b5bae0a3e3 100644 --- a/tests/ember-data__adapter/ember-cli-build.js +++ b/tests/ember-data__adapter/ember-cli-build.js @@ -5,7 +5,7 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { tests: true, 'ember-cli-babel': { throwUnlessParallelizable: true, diff --git a/tests/ember-data__adapter/package.json b/tests/ember-data__adapter/package.json index 7cf64a9edd3..463cdb0b798 100644 --- a/tests/ember-data__adapter/package.json +++ b/tests/ember-data__adapter/package.json @@ -17,6 +17,7 @@ "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", "_build:production": "pnpm build:tests -e production", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "check:types": "tsc --noEmit", "test": "bun ./diagnostic.js", "_test:production": "bun ./diagnostic.js", @@ -90,6 +91,7 @@ "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "@warp-drive/diagnostic": "workspace:5.5.0-alpha.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", diff --git a/tests/ember-data__adapter/tests/integration/belongs-to-test.js b/tests/ember-data__adapter/tests/integration/belongs-to-test.js index dad445959a4..2f13a157378 100644 --- a/tests/ember-data__adapter/tests/integration/belongs-to-test.js +++ b/tests/ember-data__adapter/tests/integration/belongs-to-test.js @@ -1,13 +1,12 @@ import EmberObject from '@ember/object'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import Store from 'ember-data__adapter/services/store'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import deepCopy from '@ember-data/unpublished-test-infra/test-support/deep-copy'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class MinimalSerializer extends EmberObject { normalizeResponse(_, __, data) { @@ -15,7 +14,7 @@ class MinimalSerializer extends EmberObject { } serialize(snapshot) { - let json = { + const json = { data: { id: snapshot.id, type: snapshot.modelName, @@ -41,11 +40,11 @@ class MinimalSerializer extends EmberObject { // minimal implementation, not json-api compliant serializeBelongsTo(snapshot, json, relationship) { - let key = relationship.name; - let belongsTo = snapshot.belongsTo(key); + const key = relationship.name; + const belongsTo = snapshot.belongsTo(key); if (belongsTo) { - let value = { + const value = { data: { id: belongsTo.id, type: belongsTo.modelName, @@ -57,11 +56,11 @@ class MinimalSerializer extends EmberObject { // minimal implementation, not json-api compliant serializeHasMany(snapshot, json, relationship) { - let key = relationship.key; - let hasMany = snapshot.hasMany(key); + const key = relationship.key; + const hasMany = snapshot.hasMany(key); if (hasMany && hasMany.length) { - let value = { + const value = { data: hasMany.map((snap) => ({ id: snap.id, type: snap.modelName, @@ -102,7 +101,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { let findRecordCalled = 0; let findBelongsToCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '3', type: 'comment', @@ -119,7 +118,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let expectedResult = { + const expectedResult = { data: { id: '2', type: 'post', @@ -139,13 +138,13 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindBelongsToAdapter extends EmberObject { findRecord() { @@ -157,7 +156,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findBelongsTo'); - let expectedURL = initialRecord.data.relationships.post.links.related; + const expectedURL = initialRecord.data.relationships.post.links.related; assert.equal(url, expectedURL, 'url is passed to findBelongsTo'); assert.equal(relationship.key, 'post', 'relationship is passed to findBelongsTo'); @@ -170,9 +169,9 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { owner.register('adapter:application', TestFindBelongsToAdapter); - let comment = store.push(initialRecord); + const comment = store.push(initialRecord); - let post = await comment.post; + const post = await comment.post; assert.equal(findRecordCalled, 0, 'findRecord is not called'); assert.equal(findBelongsToCalled, 1, 'findBelongsTo is called once'); @@ -182,7 +181,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { testInDebug( 'if a belongsTo relationship has a link but no data (findBelongsTo is undefined)', async function (assert) { - let initialRecord = { + const initialRecord = { data: { id: '3', type: 'comment', @@ -199,14 +198,14 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); class TestFindBelongsToAdapter extends EmberObject {} owner.register('adapter:application', TestFindBelongsToAdapter); - let comment = store.push(initialRecord); + const comment = store.push(initialRecord); await assert.expectAssertion(async function () { await comment.post; @@ -218,7 +217,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { let findRecordCalled = 0; let findBelongsToCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '3', type: 'comment', @@ -236,7 +235,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let expectedResult = { + const expectedResult = { data: { id: '2', type: 'post', @@ -256,13 +255,13 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindRecordAdapter extends EmberObject { findRecord(passedStore, type, id, snapshot) { @@ -285,9 +284,9 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let comment = store.push(initialRecord); + const comment = store.push(initialRecord); - let post = await comment.post; + const post = await comment.post; assert.equal(findRecordCalled, 1, 'findRecord is called once'); assert.equal(findBelongsToCalled, 0, 'findBelongsTo is not called'); @@ -297,7 +296,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { test('if a belongsTo relationship has data but not a link (findBelongsTo is not defined)', async function (assert) { let findRecordCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '3', type: 'comment', @@ -315,7 +314,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let expectedResult = { + const expectedResult = { data: { id: '2', type: 'post', @@ -335,13 +334,13 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindRecordAdapter extends EmberObject { findRecord(passedStore, type, id, snapshot) { @@ -360,9 +359,9 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let comment = store.push(initialRecord); + const comment = store.push(initialRecord); - let post = await comment.post; + const post = await comment.post; assert.equal(findRecordCalled, 1, 'findRecord is called once'); assert.deepEqual(post.serialize(), expectedResult, 'findRecord returns expected result'); @@ -372,7 +371,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { let findRecordCalled = 0; let findBelongsToCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '3', type: 'comment', @@ -393,7 +392,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let expectedResult = { + const expectedResult = { data: { id: '2', type: 'post', @@ -413,13 +412,13 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindBelongsToAdapter extends EmberObject { findRecord() { @@ -431,7 +430,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findBelongsTo'); - let expectedURL = initialRecord.data.relationships.post.links.related; + const expectedURL = initialRecord.data.relationships.post.links.related; assert.equal(url, expectedURL, 'url is passed to findBelongsTo'); assert.equal(relationship.name, 'post', 'relationship is passed to findBelongsTo'); @@ -444,9 +443,9 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { owner.register('adapter:application', TestFindBelongsToAdapter); - let comment = store.push(initialRecord); + const comment = store.push(initialRecord); - let post = await comment.post; + const post = await comment.post; assert.equal(findRecordCalled, 0, 'findRecord is not called'); assert.equal(findBelongsToCalled, 1, 'findBelongsTo is called once'); @@ -456,7 +455,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { test('if a belongsTo relationship has link and data (findBelongsTo is not defined)', async function (assert) { let findRecordCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '3', type: 'comment', @@ -474,7 +473,7 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let expectedResult = { + const expectedResult = { data: { id: '2', type: 'post', @@ -494,13 +493,13 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindRecordAdapter extends EmberObject { findRecord(passedStore, type, id, snapshot) { @@ -519,9 +518,9 @@ module('integration/belongs-to - Belongs To Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let comment = store.push(initialRecord); + const comment = store.push(initialRecord); - let post = await comment.post; + const post = await comment.post; assert.equal(findRecordCalled, 1, 'findRecord is called once'); assert.deepEqual(post.serialize(), expectedResult, 'findRecord returns expected result'); diff --git a/tests/ember-data__adapter/tests/integration/coalescing-test.js b/tests/ember-data__adapter/tests/integration/coalescing-test.js index 26f91f11f62..0f470c6d275 100644 --- a/tests/ember-data__adapter/tests/integration/coalescing-test.js +++ b/tests/ember-data__adapter/tests/integration/coalescing-test.js @@ -1,13 +1,12 @@ import EmberObject from '@ember/object'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import Store from 'ember-data__adapter/services/store'; import Model, { attr } from '@ember-data/model'; import { recordIdentifierFor } from '@ember-data/store'; import deepCopy from '@ember-data/unpublished-test-infra/test-support/deep-copy'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class MinimalSerializer extends EmberObject { normalizeResponse(_, __, data) { @@ -45,7 +44,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { test('coalesceFindRequests is true and findMany is not defined', async function (assert) { let findRecordCalled = 0; - let expectedResults = [ + const expectedResults = [ { data: { id: '12', @@ -68,13 +67,13 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { }, ]; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultsCopy = deepCopy(expectedResults); + const expectedResultsCopy = deepCopy(expectedResults); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = true; @@ -83,7 +82,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findRecord'); assert.equal(type, Person, 'model is passed to findRecord'); - let expectedId = expectedResultsCopy[findRecordCalled].data.id; + const expectedId = expectedResultsCopy[findRecordCalled].data.id; assert.equal(id, expectedId, 'id is passed to findRecord'); assert.equal(snapshot.modelName, 'person', 'snapshot is passed to findRecord with correct modelName'); @@ -95,10 +94,10 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let promises = expectedResults.map((result) => result.data.id).map((id) => store.findRecord('person', id)); - let records = await Promise.all(promises); + const promises = expectedResults.map((result) => result.data.id).map((id) => store.findRecord('person', id)); + const records = await Promise.all(promises); - let serializedRecords = records.map((record) => record.serialize()); + const serializedRecords = records.map((record) => record.serialize()); assert.equal(findRecordCalled, 2, 'findRecord is called twice'); assert.deepEqual(serializedRecords, expectedResults, 'each findRecord returns expected result'); @@ -130,13 +129,13 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { ], }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultsCopy = deepCopy(expectedResults); + const expectedResultsCopy = deepCopy(expectedResults); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = true; @@ -151,7 +150,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findMany'); assert.equal(type, Person, 'model is passed to findMany'); - let expectedIds = expectedResultsCopy.data.map((record) => record.id); + const expectedIds = expectedResultsCopy.data.map((record) => record.id); assert.deepEqual(ids, expectedIds, 'ids are passed to findMany'); snapshots.forEach((snapshot, index) => { @@ -170,10 +169,10 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let promises = expectedResults.data.map((result) => result.id).map((id) => store.findRecord('person', id)); - let records = await Promise.all(promises); + const promises = expectedResults.data.map((result) => result.id).map((id) => store.findRecord('person', id)); + const records = await Promise.all(promises); - let serializedRecords = records.slice().map((record) => record.serialize()); + const serializedRecords = records.slice().map((record) => record.serialize()); expectedResults = expectedResults.data.map((result) => ({ data: result })); assert.equal(findRecordCalled, 0, 'findRecord is not called'); @@ -185,8 +184,8 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { test('Coalescing works with multiple includes options specified (bypass findMany)', async function (assert) { let findRecordCalled = 0; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = true; @@ -227,9 +226,9 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let person1 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); - let person2 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '2' }); - let promises = [ + const person1 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); + const person2 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '2' }); + const promises = [ store.findRecord('person', '1'), // creates request (1) store.findRecord('person', '1', { include: '' }), // de-duped store.findRecord('person', '1', { include: 'users' }), // creates request (2) @@ -246,9 +245,9 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { store.findRecord('person', '2', { include: 'users' }), // de-duped store.findRecord('person', '2', { include: 'users.foo' }), // de-duped ]; - let records = await Promise.all(promises); - let foundIdentifiers = records.map((record) => recordIdentifierFor(record)); - let expectedIdentifiers = [ + const records = await Promise.all(promises); + const foundIdentifiers = records.map((record) => recordIdentifierFor(record)); + const expectedIdentifiers = [ person1, person1, person1, @@ -317,8 +316,8 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { ], }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = true; @@ -335,11 +334,11 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findMany'); assert.equal(type, Person, 'model is passed to findMany'); - let expectedIds = ['1', '2', '3', '4']; - let expectedIncludes = [undefined, 'users', 'users.foo', ['comments']]; - let expectedOptions = [undefined, undefined, { opt: '1' }, { opt: '2' }]; - let includes = snapshots.map((snapshot) => snapshot.include); - let options = snapshots.map((snapshot) => snapshot.adapterOptions); + const expectedIds = ['1', '2', '3', '4']; + const expectedIncludes = [undefined, 'users', 'users.foo', ['comments']]; + const expectedOptions = [undefined, undefined, { opt: '1' }, { opt: '2' }]; + const includes = snapshots.map((snapshot) => snapshot.include); + const options = snapshots.map((snapshot) => snapshot.adapterOptions); assert.deepEqual(ids, expectedIds, 'ids are passed to findMany'); assert.deepEqual(includes, expectedIncludes, 'includes are what was expected'); assert.deepEqual(options, expectedOptions, 'options are what was expected'); @@ -360,19 +359,19 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let person1 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); - let person2 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '2' }); - let person3 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '3' }); - let person4 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '4' }); - let promises = [ + const person1 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); + const person2 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '2' }); + const person3 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '3' }); + const person4 = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '4' }); + const promises = [ store.findRecord('person', '1'), store.findRecord('person', '2', { include: 'users' }), store.findRecord('person', '3', { include: 'users.foo', adapterOptions: { opt: '1' } }), store.findRecord('person', '4', { include: ['comments'], adapterOptions: { opt: '2' } }), ]; - let records = await Promise.all(promises); - let foundIdentifiers = records.map((record) => recordIdentifierFor(record)); - let expectedIdentifiers = [person1, person2, person3, person4]; + const records = await Promise.all(promises); + const foundIdentifiers = records.map((record) => recordIdentifierFor(record)); + const expectedIdentifiers = [person1, person2, person3, person4]; expectedResults = expectedResults.data.map((result) => ({ data: result })); assert.equal(findRecordCalled, 0, 'findRecord is not called'); @@ -415,9 +414,9 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { ], }; - let { owner } = this; - let store = owner.lookup('service:store'); - let expectedResultsCopy = deepCopy(expectedResults); + const { owner } = this; + const store = owner.lookup('service:store'); + const expectedResultsCopy = deepCopy(expectedResults); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = true; @@ -432,7 +431,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findMany'); assert.equal(type, Person, 'model is passed to findMany'); - let expectedIds = expectedResultsCopy.data.map((record) => record.id); + const expectedIds = expectedResultsCopy.data.map((record) => record.id); assert.deepEqual(ids, expectedIds, 'ids are passed to findMany'); snapshots.forEach((snapshot, index) => { @@ -446,10 +445,10 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let promises = expectedResults.data.map((result) => result.id).map((id) => store.findRecord('person', id)); - let records = await Promise.all(promises); + const promises = expectedResults.data.map((result) => result.id).map((id) => store.findRecord('person', id)); + const records = await Promise.all(promises); - let serializedRecords = records.slice().map((record) => record.serialize()); + const serializedRecords = records.slice().map((record) => record.serialize()); expectedResults = expectedResults.data.map((result) => ({ data: result })); assert.equal(findRecordCalled, 0, 'findRecord is not called'); @@ -462,7 +461,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { let findManyCalled = 0; let groupRecordsForFindManyCalled = 0; - let expectedResults = [ + const expectedResults = [ { data: { id: '12', @@ -485,13 +484,13 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { }, ]; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultsCopy = deepCopy(expectedResults); + const expectedResultsCopy = deepCopy(expectedResults); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = false; @@ -500,7 +499,7 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findRecord'); assert.equal(type, Person, 'model is passed to findRecord'); - let expectedId = expectedResultsCopy[findRecordCalled].data.id; + const expectedId = expectedResultsCopy[findRecordCalled].data.id; assert.equal(id, expectedId, 'id is passed to findRecord'); assert.equal(snapshot.modelName, 'person', 'snapshot is passed to findRecord with correct modelName'); @@ -521,10 +520,10 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let promises = expectedResults.map((result) => result.data.id).map((id) => store.findRecord('person', id)); - let records = await Promise.all(promises); + const promises = expectedResults.map((result) => result.data.id).map((id) => store.findRecord('person', id)); + const records = await Promise.all(promises); - let serializedRecords = records.map((record) => record.serialize()); + const serializedRecords = records.map((record) => record.serialize()); assert.equal(findRecordCalled, 2, 'findRecord is called twice'); assert.equal(findManyCalled, 0, 'findMany is not called'); @@ -535,8 +534,8 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { test('Coalescing accounts for multiple findRecord calls with different options by de-duping and using findRecord', async function (assert) { let findRecordCalled = 0; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); const options = [ undefined, // not de-duped since is first request seen { reload: true }, // de-dupe @@ -609,8 +608,8 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { test('Coalescing accounts for multiple findRecord calls with different options by de-duping and using findRecord (order scenario 2)', async function (assert) { let findRecordCalled = 0; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); const options = [ { include: 'comments' }, // not de-duped since first request { reload: true, include: 'comments,friends' }, // should produce a request @@ -683,8 +682,8 @@ module('integration/coalescing - Coalescing Tests', function (hooks) { test('Coalescing accounts for multiple findRecord calls with different options by de-duping and using findRecord (order scenario 3)', async function (assert) { let findRecordCalled = 0; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); const options = [ { reload: true, include: 'comments,friends' }, // not de-duped since first request undefined, // de-dupe diff --git a/tests/ember-data__adapter/tests/integration/generate-id-test.js b/tests/ember-data__adapter/tests/integration/generate-id-test.js index 89f0d5c1ede..6b63182692f 100644 --- a/tests/ember-data__adapter/tests/integration/generate-id-test.js +++ b/tests/ember-data__adapter/tests/integration/generate-id-test.js @@ -1,11 +1,10 @@ import EmberObject from '@ember/object'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import Store from 'ember-data__adapter/services/store'; import Model, { attr } from '@ember-data/model'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class MinimalSerializer extends EmberObject { normalizeResponse(_, __, data) { @@ -44,8 +43,8 @@ module('integration/generate-id - GenerateIdForRecord Tests', function (hooks) { let generateIdForRecordCalled = 0; let seq = 0; - let store = this.owner.lookup('service:store'); - let expectedProps = { + const store = this.owner.lookup('service:store'); + const expectedProps = { firstName: 'Gaurav', lastName: 'Munjal', }; @@ -60,11 +59,11 @@ module('integration/generate-id - GenerateIdForRecord Tests', function (hooks) { this.owner.register('adapter:application', TestGenerateIdForRecordAdapter); - let record = store.createRecord('person', expectedProps); + const record = store.createRecord('person', expectedProps); assert.equal(record.id, 'manually generated id 1', 'manually generated id used'); - let recordFromPeekRecord = store.peekRecord('person', record.id); + const recordFromPeekRecord = store.peekRecord('person', record.id); assert.equal(record, recordFromPeekRecord, 'peekRecord returns the same record'); assert.equal(generateIdForRecordCalled, 1, 'generateIdForRecord is called once'); @@ -78,8 +77,8 @@ module('integration/generate-id - GenerateIdForRecord Tests', function (hooks) { }); test('store.createRecord does not error if adapter.generateIdForRecord is undefined.', async function (assert) { - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { type: 'person', attributes: { @@ -93,15 +92,15 @@ module('integration/generate-id - GenerateIdForRecord Tests', function (hooks) { this.owner.register('adapter:application', TestGenerateIdForRecordAdapter); - let props = expectedData.data.attributes; - let record = store.createRecord('person', props); + const props = expectedData.data.attributes; + const record = store.createRecord('person', props); assert.deepEqual(record.serialize().data.attributes, props, 'record created without error'); }); test('store.createRecord does not error if adapter is undefined.', async function (assert) { - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { type: 'person', attributes: { @@ -111,8 +110,8 @@ module('integration/generate-id - GenerateIdForRecord Tests', function (hooks) { }, }; - let props = expectedData.data.attributes; - let record = store.createRecord('person', props); + const props = expectedData.data.attributes; + const record = store.createRecord('person', props); assert.deepEqual(record.serialize().data.attributes, props, 'record created without error'); }); diff --git a/tests/ember-data__adapter/tests/integration/has-many-test.js b/tests/ember-data__adapter/tests/integration/has-many-test.js index 11e15567023..896d2715df2 100644 --- a/tests/ember-data__adapter/tests/integration/has-many-test.js +++ b/tests/ember-data__adapter/tests/integration/has-many-test.js @@ -1,13 +1,12 @@ import EmberObject from '@ember/object'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import Store from 'ember-data__adapter/services/store'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import deepCopy from '@ember-data/unpublished-test-infra/test-support/deep-copy'; import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class MinimalSerializer extends EmberObject { normalizeResponse(_, __, data) { @@ -15,7 +14,7 @@ class MinimalSerializer extends EmberObject { } serialize(snapshot) { - let json = { + const json = { data: { id: snapshot.id, type: snapshot.modelName, @@ -41,11 +40,11 @@ class MinimalSerializer extends EmberObject { // minimal implementation, not json-api compliant serializeBelongsTo(snapshot, json, relationship) { - let key = relationship.key; - let belongsTo = snapshot.belongsTo(key); + const key = relationship.key; + const belongsTo = snapshot.belongsTo(key); if (belongsTo) { - let value = { + const value = { data: { id: belongsTo.id, type: belongsTo.modelName, @@ -57,11 +56,11 @@ class MinimalSerializer extends EmberObject { // minimal implementation, not json-api compliant serializeHasMany(snapshot, json, relationship) { - let key = relationship.key; - let hasMany = snapshot.hasMany(key); + const key = relationship.key; + const hasMany = snapshot.hasMany(key); if (hasMany && hasMany.length) { - let value = { + const value = { data: hasMany.map((snap) => ({ id: snap.id, type: snap.modelName, @@ -88,7 +87,7 @@ class Comment extends Model { post; } -let expectedResult = { +const expectedResult = { data: [ { id: '3', @@ -138,7 +137,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findManyCalled = 0; let findHasManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -155,13 +154,13 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindHasManyAdapter extends EmberObject { findRecord() { @@ -177,7 +176,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findHasMany'); - let expectedURL = initialRecord.data.relationships.comments.links.related; + const expectedURL = initialRecord.data.relationships.comments.links.related; assert.equal(url, expectedURL, 'url is passed to findHasMany'); assert.equal(relationship.name, 'comments', 'relationship is passed to findHasMany'); @@ -190,10 +189,10 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindHasManyAdapter); - let post = store.push(initialRecord); + const post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; @@ -204,7 +203,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { }); testInDebug('if a hasMany relationship has a link but no data (findHasMany is undefined)', async function (assert) { - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -221,14 +220,14 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); class TestFindHasManyAdapter extends EmberObject {} owner.register('adapter:application', TestFindHasManyAdapter); - let post = store.push(initialRecord); + const post = store.push(initialRecord); await assert.expectAssertion(async function () { await post.comments; @@ -240,7 +239,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findManyCalled = 0; let findHasManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -264,20 +263,20 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = false; findRecord(passedStore, type, id, snapshot) { - let index = findRecordCalled++; - let expectedId = initialRecord.data.relationships.comments.data[index].id; + const index = findRecordCalled++; + const expectedId = initialRecord.data.relationships.comments.data[index].id; assert.equal(passedStore, store, 'instance of store is passed to findRecord'); assert.equal(type, Comment, 'model is passed to findRecord'); @@ -300,9 +299,9 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const post = store.push(initialRecord); + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; @@ -316,7 +315,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findRecordCalled = 0; let findManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -340,20 +339,20 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = false; findRecord(passedStore, type, id, snapshot) { - let index = findRecordCalled++; - let expectedId = initialRecord.data.relationships.comments.data[index].id; + const index = findRecordCalled++; + const expectedId = initialRecord.data.relationships.comments.data[index].id; assert.equal(passedStore, store, 'instance of store is passed to findRecord'); assert.equal(type, Comment, 'model is passed to findRecord'); @@ -372,9 +371,9 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const post = store.push(initialRecord); + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; @@ -388,7 +387,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findManyCalled = 0; let findHasManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -412,13 +411,13 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindManyAdapter extends EmberObject { coalesceFindRequests = true; @@ -441,7 +440,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findMany'); assert.equal(type, Comment, 'model is passed to findMany'); - let expectedIds = expectedResultCopy.data.map((record) => record.id); + const expectedIds = expectedResultCopy.data.map((record) => record.id); assert.deepEqual(ids, expectedIds, 'ids are passed to findMany'); snapshots.forEach((snapshot, index) => { @@ -455,9 +454,9 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindManyAdapter); - let post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const post = store.push(initialRecord); + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; @@ -471,7 +470,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findRecordCalled = 0; let findManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -495,13 +494,13 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindManyAdapter extends EmberObject { coalesceFindRequests = true; @@ -520,7 +519,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findMany'); assert.equal(type, Comment, 'model is passed to findMany'); - let expectedIds = expectedResultCopy.data.map((record) => record.id); + const expectedIds = expectedResultCopy.data.map((record) => record.id); assert.deepEqual(ids, expectedIds, 'ids are passed to findMany'); snapshots.forEach((snapshot, index) => { @@ -534,9 +533,9 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindManyAdapter); - let post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const post = store.push(initialRecord); + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; @@ -550,7 +549,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findManyCalled = 0; let findHasManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -577,13 +576,13 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindHasManyAdapter extends EmberObject { findRecord() { @@ -599,7 +598,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findHasMany'); - let expectedURL = initialRecord.data.relationships.comments.links.related; + const expectedURL = initialRecord.data.relationships.comments.links.related; assert.equal(url, expectedURL, 'url is passed to findHasMany'); assert.equal(relationship.name, 'comments', 'relationship is passed to findHasMany'); @@ -612,10 +611,10 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindHasManyAdapter); - let post = store.push(initialRecord); + const post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; @@ -629,7 +628,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findRecordCalled = 0; let findManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -656,13 +655,13 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindManyAdapter extends EmberObject { coalesceFindRequests = true; @@ -681,7 +680,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { assert.equal(passedStore, store, 'instance of store is passed to findMany'); assert.equal(type, Comment, 'model is passed to findMany'); - let expectedIds = expectedResultCopy.data.map((record) => record.id); + const expectedIds = expectedResultCopy.data.map((record) => record.id); assert.deepEqual(ids, expectedIds, 'ids are passed to findMany'); snapshots.forEach((snapshot, index) => { @@ -695,9 +694,9 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindManyAdapter); - let post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const post = store.push(initialRecord); + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; @@ -710,7 +709,7 @@ module('integration/has-many - Has Many Tests', function (hooks) { let findRecordCalled = 0; let findManyCalled = 0; - let initialRecord = { + const initialRecord = { data: { id: '2', type: 'post', @@ -734,20 +733,20 @@ module('integration/has-many - Has Many Tests', function (hooks) { }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindRecordAdapter extends EmberObject { coalesceFindRequests = false; findRecord(passedStore, type, id, snapshot) { - let index = findRecordCalled++; - let expectedId = initialRecord.data.relationships.comments.data[index].id; + const index = findRecordCalled++; + const expectedId = initialRecord.data.relationships.comments.data[index].id; assert.equal(passedStore, store, 'instance of store is passed to findRecord'); assert.equal(type, Comment, 'model is passed to findRecord'); @@ -766,9 +765,9 @@ module('integration/has-many - Has Many Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let post = store.push(initialRecord); - let comments = await post.comments; - let serializedComments = { + const post = store.push(initialRecord); + const comments = await post.comments; + const serializedComments = { data: comments.slice().map((comment) => comment.serialize().data), }; diff --git a/tests/ember-data__adapter/tests/integration/mutations-test.js b/tests/ember-data__adapter/tests/integration/mutations-test.js index 24c25515c63..e830cd761d6 100644 --- a/tests/ember-data__adapter/tests/integration/mutations-test.js +++ b/tests/ember-data__adapter/tests/integration/mutations-test.js @@ -1,11 +1,10 @@ import EmberObject from '@ember/object'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import Store from 'ember-data__adapter/services/store'; import Model, { attr } from '@ember-data/model'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class MinimalSerializer extends EmberObject { normalizeResponse(_, __, data) { @@ -42,8 +41,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { test('store.deleteRecord calls adapter.deleteRecord if a record is deleted and then saved', async function (assert) { let deleteRecordCalled = 0; - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { id: '12', type: 'person', @@ -58,8 +57,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { deleteRecord(passedStore, type, snapshot) { deleteRecordCalled++; - let data = snapshot.serialize(); - let id = snapshot.id; + const data = snapshot.serialize(); + const id = snapshot.id; assert.equal(passedStore, store, 'instance of store is passed to deleteRecord'); assert.equal(type, Person, 'model is passed to deleteRecord'); @@ -72,7 +71,7 @@ module('integration/mutations - Mutations Tests', function (hooks) { this.owner.register('adapter:application', TestDeleteRecordAdapter); - let record = store.push(expectedData); + const record = store.push(expectedData); record.deleteRecord(); await record.save(); @@ -83,8 +82,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { test('store.deleteRecord calls adapter.deleteRecord if a newly created record is persisted, then deleted and then saved', async function (assert) { let createRecordCalled = 0; let deleteRecordCalled = 0; - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { id: '12', type: 'person', @@ -99,8 +98,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { createRecord(passedStore, type, snapshot) { createRecordCalled++; - let data = snapshot.serialize(); - let id = snapshot.id; + const data = snapshot.serialize(); + const id = snapshot.id; assert.equal(passedStore, store, 'instance of store is passed to deleteRecord'); assert.equal(type, Person, 'model is passed to deleteRecord'); @@ -115,8 +114,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { deleteRecord(passedStore, type, snapshot) { deleteRecordCalled++; - let data = snapshot.serialize(); - let id = snapshot.id; + const data = snapshot.serialize(); + const id = snapshot.id; assert.equal(passedStore, store, 'instance of store is passed to deleteRecord'); assert.equal(type, Person, 'model is passed to deleteRecord'); @@ -129,8 +128,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { this.owner.register('adapter:application', TestDeleteRecordAdapter); - let props = { id: expectedData.data.id, ...expectedData.data.attributes }; - let record = store.createRecord('person', props); + const props = { id: expectedData.data.id, ...expectedData.data.attributes }; + const record = store.createRecord('person', props); await record.save(); assert.equal(createRecordCalled, 1, 'createRecord is called once'); @@ -144,8 +143,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { test('store.deleteRecord does not call adapter.deleteRecord if a newly created, unpersisted record is deleted and then saved', async function (assert) { let createRecordCalled = 0; let deleteRecordCalled = 0; - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { id: '12', type: 'person', @@ -168,8 +167,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { this.owner.register('adapter:application', TestDeleteRecordAdapter); - let props = { id: expectedData.data.id, ...expectedData.data.attributes }; - let record = store.createRecord('person', props); + const props = { id: expectedData.data.id, ...expectedData.data.attributes }; + const record = store.createRecord('person', props); record.deleteRecord(); await record.save(); @@ -180,8 +179,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { test('record.save() calls adapter.createRecord if a newly created record unpersisted record is saved', async function (assert) { let createRecordCalled = 0; - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { id: '12', type: 'person', @@ -196,8 +195,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { createRecord(passedStore, type, snapshot) { createRecordCalled++; - let data = snapshot.serialize(); - let id = snapshot.id; + const data = snapshot.serialize(); + const id = snapshot.id; assert.equal(passedStore, store, 'instance of store is passed to deleteRecord'); assert.equal(type, Person, 'model is passed to deleteRecord'); @@ -212,8 +211,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { this.owner.register('adapter:application', TestCreateRecordAdapter); - let props = { id: expectedData.data.id, ...expectedData.data.attributes }; - let record = store.createRecord('person', props); + const props = { id: expectedData.data.id, ...expectedData.data.attributes }; + const record = store.createRecord('person', props); await record.save(); assert.equal(createRecordCalled, 1, 'createRecord is called once'); @@ -222,8 +221,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { test('record.save() calls adapter.createRecord then adapter.updateRecord if a newly created record record is saved, then saved again', async function (assert) { let createRecordCalled = 0; let updateRecord = 0; - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { id: '12', type: 'person', @@ -238,8 +237,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { createRecord(passedStore, type, snapshot) { createRecordCalled++; - let data = snapshot.serialize(); - let id = snapshot.id; + const data = snapshot.serialize(); + const id = snapshot.id; assert.equal(passedStore, store, 'instance of store is passed to deleteRecord'); assert.equal(type, Person, 'model is passed to deleteRecord'); @@ -254,8 +253,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { updateRecord(passedStore, type, snapshot) { updateRecord++; - let data = snapshot.serialize(); - let id = snapshot.id; + const data = snapshot.serialize(); + const id = snapshot.id; assert.equal(passedStore, store, 'instance of store is passed to deleteRecord'); assert.equal(type, Person, 'model is passed to deleteRecord'); @@ -270,8 +269,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { this.owner.register('adapter:application', TestUpdateRecordAdapter); - let props = { id: expectedData.data.id, ...expectedData.data.attributes }; - let record = store.createRecord('person', props); + const props = { id: expectedData.data.id, ...expectedData.data.attributes }; + const record = store.createRecord('person', props); await record.save(); assert.equal(createRecordCalled, 1, 'createRecord is called once'); @@ -287,8 +286,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { test('record.save() calls adapter.updateRecord if an existing persisted record is saved', async function (assert) { let createRecordCalled = 0; let updateRecord = 0; - let store = this.owner.lookup('service:store'); - let expectedData = { + const store = this.owner.lookup('service:store'); + const expectedData = { data: { id: '12', type: 'person', @@ -307,8 +306,8 @@ module('integration/mutations - Mutations Tests', function (hooks) { updateRecord(passedStore, type, snapshot) { updateRecord++; - let data = snapshot.serialize(); - let id = snapshot.id; + const data = snapshot.serialize(); + const id = snapshot.id; assert.equal(passedStore, store, 'instance of store is passed to deleteRecord'); assert.equal(type, Person, 'model is passed to deleteRecord'); @@ -323,7 +322,7 @@ module('integration/mutations - Mutations Tests', function (hooks) { this.owner.register('adapter:application', TestUpdateRecordAdapter); - let record = store.push(expectedData); + const record = store.push(expectedData); record.firstName = 'Kevin'; expectedData.data.attributes.firstName = 'Kevin'; diff --git a/tests/ember-data__adapter/tests/integration/queries-test.js b/tests/ember-data__adapter/tests/integration/queries-test.js index 3593b6b4306..021d5b6588d 100644 --- a/tests/ember-data__adapter/tests/integration/queries-test.js +++ b/tests/ember-data__adapter/tests/integration/queries-test.js @@ -1,12 +1,11 @@ import EmberObject from '@ember/object'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import Store from 'ember-data__adapter/services/store'; import Model, { attr } from '@ember-data/model'; import deepCopy from '@ember-data/unpublished-test-infra/test-support/deep-copy'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class MinimalSerializer extends EmberObject { normalizeResponse(_, __, data) { @@ -42,10 +41,10 @@ module('integration/queries - Queries Tests', function (hooks) { }); test('options passed to adapters by LegacyHandler are mutable', async function (assert) { - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); - let expectedResult = { + const expectedResult = { id: '19', type: 'person', attributes: { @@ -87,15 +86,15 @@ module('integration/queries - Queries Tests', function (hooks) { owner.register('adapter:application', TestAdapter); - for (let method of ['query', 'queryRecord']) { - let result = await store[method]('person', { initialOption: 'foo' }); + for (const method of ['query', 'queryRecord']) { + const result = await store[method]('person', { initialOption: 'foo' }); assert.ok(result, `result is returned for ${method}`); } }); test('store.findRecord calls adapter.findRecord w/correct args', async function (assert) { let findRecordCalled = 0; - let expectedResult = { + const expectedResult = { data: { id: '12', type: 'person', @@ -105,13 +104,13 @@ module('integration/queries - Queries Tests', function (hooks) { }, }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); class TestFindRecordAdapter extends EmberObject { findRecord(passedStore, type, id, snapshot) { @@ -130,7 +129,7 @@ module('integration/queries - Queries Tests', function (hooks) { owner.register('adapter:application', TestFindRecordAdapter); - let record = await store.findRecord('person', '12'); + const record = await store.findRecord('person', '12'); assert.equal(findRecordCalled, 1, 'findRecord is called once'); assert.deepEqual(record.serialize(), expectedResult, 'findRecord returns expected result'); @@ -162,10 +161,10 @@ module('integration/queries - Queries Tests', function (hooks) { // This code is a workaround for issue https://github.com/emberjs/data/issues/6758 // expectedResult is mutated during store.findRecord // to add the lid - let expectedResultCopy = deepCopy(expectedResult); + const expectedResultCopy = deepCopy(expectedResult); - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); class TestFindAllAdapter extends EmberObject { findAll(passedStore, type, sinceToken, snapshot) { @@ -183,9 +182,9 @@ module('integration/queries - Queries Tests', function (hooks) { owner.register('adapter:application', TestFindAllAdapter); - let manyArray = await store.findAll('person'); + const manyArray = await store.findAll('person'); - let result = manyArray.slice().map((person) => person.serialize()); + const result = manyArray.slice().map((person) => person.serialize()); expectedResult = expectedResult.data.map((person) => ({ data: person })); assert.equal(findAllCalled, 1, 'findAll is called once'); @@ -194,7 +193,7 @@ module('integration/queries - Queries Tests', function (hooks) { test('store.queryRecord calls adapter.queryRecord w/correct args', async function (assert) { let queryRecordCalled = 0; - let expectedResult = { + const expectedResult = { data: { id: '12', type: 'person', @@ -204,8 +203,8 @@ module('integration/queries - Queries Tests', function (hooks) { }, }, }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); class TestQueryRecordAdapter extends EmberObject { queryRecord(passedStore, type, query, options) { @@ -222,7 +221,7 @@ module('integration/queries - Queries Tests', function (hooks) { owner.register('adapter:application', TestQueryRecordAdapter); - let record = await store.queryRecord('person', { firstName: 'Gaurav' }); + const record = await store.queryRecord('person', { firstName: 'Gaurav' }); assert.equal(queryRecordCalled, 1, 'queryRecord is called once'); assert.deepEqual(record.serialize(), expectedResult, 'queryRecord returns expected result'); @@ -250,8 +249,8 @@ module('integration/queries - Queries Tests', function (hooks) { }, ], }; - let { owner } = this; - let store = owner.lookup('service:store'); + const { owner } = this; + const store = owner.lookup('service:store'); class TestQueryAdapter extends EmberObject { query(passedStore, type, query, recordArray, options) { @@ -269,9 +268,9 @@ module('integration/queries - Queries Tests', function (hooks) { owner.register('adapter:application', TestQueryAdapter); - let manyArray = await store.query('person', { firstName: 'Chris' }); + const manyArray = await store.query('person', { firstName: 'Chris' }); - let result = manyArray.slice().map((person) => person.serialize()); + const result = manyArray.slice().map((person) => person.serialize()); expectedResult = expectedResult.data.map((person) => ({ data: person })); assert.equal(queryCalled, 1, 'query is called once'); diff --git a/tests/ember-data__adapter/tests/integration/reload-test.js b/tests/ember-data__adapter/tests/integration/reload-test.js index ff5521364a5..db6a85c4327 100644 --- a/tests/ember-data__adapter/tests/integration/reload-test.js +++ b/tests/ember-data__adapter/tests/integration/reload-test.js @@ -1,11 +1,10 @@ import EmberObject from '@ember/object'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import Store from 'ember-data__adapter/services/store'; import Model, { attr } from '@ember-data/model'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class MinimalSerializer extends EmberObject { normalizeResponse(_, __, data) { @@ -247,7 +246,7 @@ module('integration/reload - Reloading Tests', function (hooks) { module('adapter.shouldReloadRecord', function () { test('adapter.shouldReloadRecord is not called when store.findRecord is called for an unloaded record (but we do make request)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -263,7 +262,7 @@ module('integration/reload - Reloading Tests', function (hooks) { resolveFindRecordWith: payload, }); - let record = this.store.push(payload); + const record = this.store.push(payload); this.store.unloadRecord(record); @@ -274,7 +273,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldReloadRecord is not called when store.findRecord is called for a never loaded record (but we do make request)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -297,7 +296,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldReloadRecord is not called when store.findRecord is called with a reload flag (but we do make request if reload is true)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -322,7 +321,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldReloadRecord is not called when store.findRecord is called with a reload flag (and we do not make request if reload is false)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -347,7 +346,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('if adapter.shouldReloadRecord is undefined, we default to false and do not make a request', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -372,7 +371,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldReloadRecord is called when store.findRecord is called without a reload flag (shouldReloadRecord returns true)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -398,7 +397,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldReloadRecord is called when store.findRecord is called without a reload flag (shouldReloadRecord returns false)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -426,7 +425,7 @@ module('integration/reload - Reloading Tests', function (hooks) { module('adapter.shouldBackgroundReloadRecord', function () { test('adapter.shouldBackgroundReloadRecord is not called when store.findRecord is called for an unloaded record (but we do make request)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -441,7 +440,7 @@ module('integration/reload - Reloading Tests', function (hooks) { resolveFindRecordWith: payload, }); - let record = this.store.push(payload); + const record = this.store.push(payload); this.store.unloadRecord(record); @@ -452,7 +451,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldBackgroundReloadRecord is not called when store.findRecord is called for a never loaded record (but we do make request)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -474,7 +473,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldBackgroundReloadRecord is not called called when store.findRecord is called with reload: true flag (but we do make request)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -498,7 +497,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldBackgroundReloadRecord is not called called when store.findRecord is called and shouldReloadRecord returns true (but we do make request)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -523,7 +522,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldBackgroundReloadRecord is not called when store.findRecord is called with backroundReload as an option (backgroundReload is true)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -548,7 +547,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldBackgroundReloadRecord is not called when store.findRecord is called with backroundReload as an option (backgroundReload is false)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -572,7 +571,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('store.findRecord does not error if adapter.shouldBackgroundReloadRecord is undefined and backgroundReload is not present.', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -596,7 +595,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldBackgroundReloadRecord is called when store.findRecord is called and there is no backgroundReload flag (adapter.shouldBackgroundReloadRecord() returns true)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', @@ -622,7 +621,7 @@ module('integration/reload - Reloading Tests', function (hooks) { }); test('adapter.shouldBackgroundReloadRecord is called when store.findRecord is called and there is no backgroundReload flag (adapter.shouldBackgroundReloadRecord() returns false)', async function (assert) { - let payload = { + const payload = { data: { id: '1', type: 'person', diff --git a/tests/ember-data__adapter/tests/test-helper.js b/tests/ember-data__adapter/tests/test-helper.js index 595269a528f..7589fecb246 100644 --- a/tests/ember-data__adapter/tests/test-helper.js +++ b/tests/ember-data__adapter/tests/test-helper.js @@ -1,11 +1,10 @@ import { setApplication } from '@ember/test-helpers'; +import configureAsserts from '@ember-data/unpublished-test-infra/test-support/asserts'; import { setupGlobalHooks } from '@warp-drive/diagnostic'; import { configure } from '@warp-drive/diagnostic/ember'; import { start } from '@warp-drive/diagnostic/runners/dom'; -import configureAsserts from '@ember-data/unpublished-test-infra/test-support/asserts'; - import Application from '../app'; import config from '../config/environment'; From 9bb380493fc16c317e26a79739969c9665612b65 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 09:52:19 -0800 Subject: [PATCH 04/17] Add eslintrc for tests/graph --- pnpm-lock.yaml | 3 ++ tests/ember-data__graph/.eslintrc.cjs | 39 +++++++++++++++++++ tests/ember-data__graph/app/services/store.ts | 5 +-- tests/ember-data__graph/config/environment.js | 2 +- tests/ember-data__graph/ember-cli-build.js | 4 +- tests/ember-data__graph/package.json | 2 + .../graph/diff-preservation-test.ts | 9 ++--- .../integration/graph/duplicate-data-test.ts | 10 ++--- .../abstract-edge-removal-test.ts | 4 +- .../integration/graph/edge-removal/helpers.ts | 11 +++--- .../integration/graph/edge-removal/setup.ts | 17 ++++---- .../tests/integration/graph/edge-test.ts | 9 +++-- .../tests/integration/graph/graph-test.ts | 5 +-- .../graph/order-preservation-test.ts | 9 +++-- .../graph/polymorphism/implicit-keys-test.ts | 10 +++-- .../tests/integration/graph/unload-test.ts | 9 +++-- tests/ember-data__graph/tests/setup-test.ts | 3 +- tests/ember-data__graph/tests/test-helper.js | 3 +- 18 files changed, 97 insertions(+), 57 deletions(-) create mode 100644 tests/ember-data__graph/.eslintrc.cjs diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8e80340f95..32f17a5aa66 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2694,6 +2694,9 @@ importers: '@warp-drive/diagnostic': specifier: workspace:5.5.0-alpha.11 version: file:packages/diagnostic(@ember/test-helpers@3.2.0)(@embroider/addon-shim@1.8.7)(ember-cli-test-loader@3.1.0) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-auto-import: specifier: ^2.6.3 version: 2.6.3(webpack@5.89.0) diff --git a/tests/ember-data__graph/.eslintrc.cjs b/tests/ember-data__graph/.eslintrc.cjs new file mode 100644 index 00000000000..827dc3d3969 --- /dev/null +++ b/tests/ember-data__graph/.eslintrc.cjs @@ -0,0 +1,39 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const diagnostic = require('@warp-drive/internal-config/eslint/diagnostic.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config({ + files: ['ember-cli-build.js', 'testem.js'], + }), + node.defaults({ + files: ['./config/environment.js', './config/targets.js'], + }), + typescript.defaults(), + diagnostic.defaults({ + files: ['tests/**/*.{js,ts}'], + }), + ], +}; diff --git a/tests/ember-data__graph/app/services/store.ts b/tests/ember-data__graph/app/services/store.ts index 33a046b1899..3a52705a78e 100644 --- a/tests/ember-data__graph/app/services/store.ts +++ b/tests/ember-data__graph/app/services/store.ts @@ -1,5 +1,3 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; - import JSONAPICache from '@ember-data/json-api'; import { adapterFor, @@ -16,7 +14,8 @@ import RequestManager from '@ember-data/request'; import Fetch from '@ember-data/request/fetch'; import BaseStore, { CacheHandler } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; export default class Store extends BaseStore { constructor(args: unknown) { diff --git a/tests/ember-data__graph/config/environment.js b/tests/ember-data__graph/config/environment.js index d9e0a92ad97..94e67a34e77 100644 --- a/tests/ember-data__graph/config/environment.js +++ b/tests/ember-data__graph/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'ember-data__graph', environment, rootURL: '/', diff --git a/tests/ember-data__graph/ember-cli-build.js b/tests/ember-data__graph/ember-cli-build.js index d26fe6ad220..bd540a4814b 100644 --- a/tests/ember-data__graph/ember-cli-build.js +++ b/tests/ember-data__graph/ember-cli-build.js @@ -1,4 +1,4 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); @@ -27,7 +27,7 @@ module.exports = function (defaults) { env: require('@ember-data/private-build-infra/src/utilities/get-env')(), }; - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { emberData: Object.assign({}, config), tests: true, babel: { diff --git a/tests/ember-data__graph/package.json b/tests/ember-data__graph/package.json index 8910487c8ee..3a2294f60ff 100644 --- a/tests/ember-data__graph/package.json +++ b/tests/ember-data__graph/package.json @@ -17,6 +17,7 @@ "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", "build:production": "pnpm build:tests -e production", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "check:types": "tsc --noEmit", "test": "bun ./diagnostic.js", "test:production": "bun ./diagnostic.js", @@ -92,6 +93,7 @@ "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "@warp-drive/diagnostic": "workspace:5.5.0-alpha.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", diff --git a/tests/ember-data__graph/tests/integration/graph/diff-preservation-test.ts b/tests/ember-data__graph/tests/integration/graph/diff-preservation-test.ts index 10493cb71d1..513bde15295 100644 --- a/tests/ember-data__graph/tests/integration/graph/diff-preservation-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/diff-preservation-test.ts @@ -1,11 +1,12 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - +// Remove once @hasMany is typed +/* eslint-disable @typescript-eslint/no-unsafe-call */ // @ts-expect-error TODO: This is supplied via private-build-infra/virtual-packages import { DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE } from '@ember-data/deprecations'; import { graphFor } from '@ember-data/graph/-private'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import type Store from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; import { deprecatedTest } from '../../setup-test'; @@ -24,7 +25,6 @@ module('Integration | Graph | Diff Preservation', function (hooks) { class App extends Model { @attr declare name: string; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call @hasMany('config', { async: false, inverse: null }) declare configs: Config[]; } @@ -84,7 +84,6 @@ module('Integration | Graph | Diff Preservation', function (hooks) { class App extends Model { @attr declare name: string; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call @hasMany('config', { async: false, inverse: null }) declare configs: Config[]; } diff --git a/tests/ember-data__graph/tests/integration/graph/duplicate-data-test.ts b/tests/ember-data__graph/tests/integration/graph/duplicate-data-test.ts index 861ff4cf6df..695f7e3c9b8 100644 --- a/tests/ember-data__graph/tests/integration/graph/duplicate-data-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/duplicate-data-test.ts @@ -1,12 +1,12 @@ -import { module } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - +/* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */ // @ts-expect-error TODO: This is supplied via private-build-infra/virtual-packages import { DEPRECATE_NON_UNIQUE_PAYLOADS } from '@ember-data/deprecations'; import { graphFor } from '@ember-data/graph/-private'; import Model, { attr, hasMany } from '@ember-data/model'; import type Store from '@ember-data/store'; import { test } from '@ember-data/unpublished-test-infra/test-support/test-in-debug'; +import { module } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; import { deprecatedTest } from '../../setup-test'; @@ -25,7 +25,6 @@ module('Integration | Graph | Duplicate Data', function (hooks) { class App extends Model { @attr declare name: string; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call @hasMany('config', { async: false, inverse: null }) declare configs: Config[]; } @@ -85,7 +84,6 @@ module('Integration | Graph | Duplicate Data', function (hooks) { class App extends Model { @attr declare name: string; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call @hasMany('config', { async: false, inverse: null }) declare configs: Config[]; } @@ -141,7 +139,6 @@ module('Integration | Graph | Duplicate Data', function (hooks) { class App extends Model { @attr declare name: string; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call @hasMany('config', { async: false, inverse: null }) declare configs: Config[]; } @@ -188,7 +185,6 @@ module('Integration | Graph | Duplicate Data', function (hooks) { class App extends Model { @attr declare name: string; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call @hasMany('config', { async: false, inverse: null }) declare configs: Config[]; } diff --git a/tests/ember-data__graph/tests/integration/graph/edge-removal/abstract-edge-removal-test.ts b/tests/ember-data__graph/tests/integration/graph/edge-removal/abstract-edge-removal-test.ts index dc03878ad6d..5c15a0ec175 100644 --- a/tests/ember-data__graph/tests/integration/graph/edge-removal/abstract-edge-removal-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/edge-removal/abstract-edge-removal-test.ts @@ -152,9 +152,9 @@ module('Integration | Graph | Edge Removal', function (hooks) { */ // we remove if the record was new or if the relationship was sync (client side delete semantics) - let removed = config.useCreate || !config.async; + const removed = config.useCreate || !config.async; // we clear new records, or sync non-implicit relationships (client side delete semantics) - let cleared = config.useCreate || (!config.async && !config.inverseNull); + const cleared = config.useCreate || (!config.async && !config.inverseNull); testFinalState(this, testState, config, { removed, cleared, implicitCleared: true }, assert); }); diff --git a/tests/ember-data__graph/tests/integration/graph/edge-removal/helpers.ts b/tests/ember-data__graph/tests/integration/graph/edge-removal/helpers.ts index e4b3b35da62..0cdeebd9f69 100644 --- a/tests/ember-data__graph/tests/integration/graph/edge-removal/helpers.ts +++ b/tests/ember-data__graph/tests/integration/graph/edge-removal/helpers.ts @@ -1,9 +1,10 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; -import { type Diagnostic } from '@warp-drive/diagnostic'; - +// Remove this disable once @belongsTo is typed +/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */ import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import { recordIdentifierFor } from '@ember-data/store'; -import { CollectionResourceDocument, SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; +import type { CollectionResourceDocument, SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; +import type { Diagnostic } from '@warp-drive/diagnostic'; import type { Context, UserRecord } from './setup'; import { stateOf } from './setup'; @@ -83,7 +84,7 @@ type BestFriendRel = { function makeRel(id: string | null, isMany: false): BestFriendRel; function makeRel(id: string | null, isMany: true): BestFriendRel; function makeRel(id: string | null, isMany: boolean): BestFriendRel { - let ref = { type: 'user', id: id as string } as const; + const ref = { type: 'user', id: id as string } as const; const data = isMany ? (id === null ? [] : [ref]) : id === null ? null : ref; return { bestFriends: { data } }; diff --git a/tests/ember-data__graph/tests/integration/graph/edge-removal/setup.ts b/tests/ember-data__graph/tests/integration/graph/edge-removal/setup.ts index 58072936a03..abf1492d1c7 100644 --- a/tests/ember-data__graph/tests/integration/graph/edge-removal/setup.ts +++ b/tests/ember-data__graph/tests/integration/graph/edge-removal/setup.ts @@ -1,8 +1,4 @@ -import { TestContext } from '@ember/test-helpers'; - -import type { StableRecordIdentifier } from '@warp-drive/core-types'; -import type { EmberHooks } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import { graphFor } from '@ember-data/graph/-private'; import type { CollectionEdge } from '@ember-data/graph/-private/edges/collection'; @@ -11,7 +7,9 @@ import type { ResourceEdge } from '@ember-data/graph/-private/edges/resource'; import type { Graph, GraphEdge } from '@ember-data/graph/-private/graph'; import type Model from '@ember-data/model'; import type Store from '@ember-data/store'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; import type { RecordInstance } from '@ember-data/store/-types/q/record-instance'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; import type { CollectionRelationship } from '@warp-drive/core-types/cache/relationship'; import type { CollectionResourceDocument, @@ -19,7 +17,8 @@ import type { JsonApiDocument, SingleResourceDocument, } from '@warp-drive/core-types/spec/raw'; -import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { EmberHooks } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class AbstractMap { constructor( @@ -29,7 +28,7 @@ class AbstractMap { ) {} has(identifier: StableRecordIdentifier) { - let graph = graphFor(this.store); + const graph = graphFor(this.store); return graph.identifiers.has(identifier); } } @@ -53,10 +52,10 @@ class AbstractGraph { getImplicit(identifier: StableRecordIdentifier): Record { const rels = graphFor(this.store).identifiers.get(identifier); - let implicits = Object.create(null) as Record; + const implicits = Object.create(null) as Record; if (rels) { Object.keys(rels).forEach((key) => { - let rel = rels[key]!; + const rel = rels[key]!; if (rel && isImplicit(rel)) { implicits[key] = rel; } diff --git a/tests/ember-data__graph/tests/integration/graph/edge-test.ts b/tests/ember-data__graph/tests/integration/graph/edge-test.ts index 55988c7e53f..d028cb76b13 100644 --- a/tests/ember-data__graph/tests/integration/graph/edge-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/edge-test.ts @@ -1,12 +1,13 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - +// Remove this disable once @belongsTo is typed +/* eslint-disable @typescript-eslint/no-unsafe-call */ import { graphFor } from '@ember-data/graph/-private'; import type { Graph } from '@ember-data/graph/-private/graph'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import type Store from '@ember-data/store'; import { recordIdentifierFor } from '@ember-data/store'; import { peekCache } from '@ember-data/store/-private'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; import { stateOf } from './edge-removal/setup'; @@ -71,7 +72,7 @@ module('Integration | Graph | Edges', function (hooks) { 'We still have no record data instance after push of only an identifier within a relationship' ); - let state = stateOf(graph, bestFriend); + const state = stateOf(graph, bestFriend); assert.deepEqual(state.remote, [identifier2], 'Our initial canonical state is correct'); assert.deepEqual(state.local, [identifier2], 'Our initial current state is correct'); diff --git a/tests/ember-data__graph/tests/integration/graph/graph-test.ts b/tests/ember-data__graph/tests/integration/graph/graph-test.ts index 1a5b3219dba..0a5eb668094 100644 --- a/tests/ember-data__graph/tests/integration/graph/graph-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/graph-test.ts @@ -1,8 +1,7 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - import { graphFor } from '@ember-data/graph/-private'; import Store from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; module('Integration | Graph | Configuration', function (hooks) { setupTest(hooks); diff --git a/tests/ember-data__graph/tests/integration/graph/order-preservation-test.ts b/tests/ember-data__graph/tests/integration/graph/order-preservation-test.ts index ed7653b2019..5ddcfc6fa6e 100644 --- a/tests/ember-data__graph/tests/integration/graph/order-preservation-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/order-preservation-test.ts @@ -1,9 +1,10 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - +// Remove this disable once @belongsTo and @hasMany are typed +/* eslint-disable @typescript-eslint/no-unsafe-call */ import { graphFor } from '@ember-data/graph/-private'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; -import Store from '@ember-data/store'; +import type Store from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; class App extends Model { @attr declare name: string; diff --git a/tests/ember-data__graph/tests/integration/graph/polymorphism/implicit-keys-test.ts b/tests/ember-data__graph/tests/integration/graph/polymorphism/implicit-keys-test.ts index 226c9cfdbb6..54b55aa8c4c 100644 --- a/tests/ember-data__graph/tests/integration/graph/polymorphism/implicit-keys-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/polymorphism/implicit-keys-test.ts @@ -1,9 +1,11 @@ -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - +// Remove this disable once @belongsTo is typed +/* eslint-disable @typescript-eslint/no-unsafe-call */ import { graphFor } from '@ember-data/graph/-private'; import Model, { attr, belongsTo } from '@ember-data/model'; -import Store, { recordIdentifierFor } from '@ember-data/store'; +import type Store from '@ember-data/store'; +import { recordIdentifierFor } from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; module('Integration | Graph | Implicit Keys', function (hooks) { setupTest(hooks); diff --git a/tests/ember-data__graph/tests/integration/graph/unload-test.ts b/tests/ember-data__graph/tests/integration/graph/unload-test.ts index da2e08e5902..9f8cf7b16c8 100644 --- a/tests/ember-data__graph/tests/integration/graph/unload-test.ts +++ b/tests/ember-data__graph/tests/integration/graph/unload-test.ts @@ -1,12 +1,13 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; - +// Remove this disable once @belongsTo is typed +/* eslint-disable @typescript-eslint/no-unsafe-call */ import { graphFor } from '@ember-data/graph/-private'; import type { ResourceEdge } from '@ember-data/graph/-private/edges/resource'; import type { Graph } from '@ember-data/graph/-private/graph'; import Model, { attr, belongsTo } from '@ember-data/model'; import type Store from '@ember-data/store'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; module('Integration | Graph | Unload', function (hooks) { setupTest(hooks); diff --git a/tests/ember-data__graph/tests/setup-test.ts b/tests/ember-data__graph/tests/setup-test.ts index ec40c8f4d68..057e39a0896 100644 --- a/tests/ember-data__graph/tests/setup-test.ts +++ b/tests/ember-data__graph/tests/setup-test.ts @@ -1,5 +1,4 @@ -import { skip, test } from '@warp-drive/diagnostic'; - import { createDeprecatedTestFn } from '@ember-data/unpublished-test-infra/test-support/test'; +import { skip, test } from '@warp-drive/diagnostic'; export const deprecatedTest = createDeprecatedTestFn({ skip, test }); diff --git a/tests/ember-data__graph/tests/test-helper.js b/tests/ember-data__graph/tests/test-helper.js index 595269a528f..7589fecb246 100644 --- a/tests/ember-data__graph/tests/test-helper.js +++ b/tests/ember-data__graph/tests/test-helper.js @@ -1,11 +1,10 @@ import { setApplication } from '@ember/test-helpers'; +import configureAsserts from '@ember-data/unpublished-test-infra/test-support/asserts'; import { setupGlobalHooks } from '@warp-drive/diagnostic'; import { configure } from '@warp-drive/diagnostic/ember'; import { start } from '@warp-drive/diagnostic/runners/dom'; -import configureAsserts from '@ember-data/unpublished-test-infra/test-support/asserts'; - import Application from '../app'; import config from '../config/environment'; From dd85101e39c38f68cb3b6ef2c090f182733abde1 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 10:14:29 -0800 Subject: [PATCH 05/17] Add eslintrc for tests/json-api --- config/eslint/diagnostic.cjs | 1 + pnpm-lock.yaml | 3 ++ tests/ember-data__json-api/.eslintrc.cjs | 39 +++++++++++++++++++ .../config/environment.js | 2 +- tests/ember-data__json-api/ember-cli-build.js | 4 +- tests/ember-data__json-api/package.json | 2 + .../cache/collection-data-documents-test.ts | 18 ++++----- .../integration/cache/meta-documents-test.ts | 10 ++--- .../cache/resource-data-documents-test.ts | 16 ++++---- .../tests/integration/serialize-test.ts | 9 ++--- 10 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 tests/ember-data__json-api/.eslintrc.cjs diff --git a/config/eslint/diagnostic.cjs b/config/eslint/diagnostic.cjs index 05439b5a761..3441ad18777 100644 --- a/config/eslint/diagnostic.cjs +++ b/config/eslint/diagnostic.cjs @@ -12,6 +12,7 @@ function defaults(config = {}) { }), config?.rules, { + 'qunit/require-expect': 'off', 'qunit/no-assert-equal': 'off', 'qunit/no-conditional-assertions': 'off', 'qunit/no-ok-equality': 'off', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32f17a5aa66..942a38627fd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2861,6 +2861,9 @@ importers: '@warp-drive/diagnostic': specifier: workspace:5.5.0-alpha.11 version: file:packages/diagnostic(@ember/test-helpers@3.2.0)(@embroider/addon-shim@1.8.7)(ember-cli-test-loader@3.1.0) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-auto-import: specifier: ^2.6.3 version: 2.6.3(webpack@5.89.0) diff --git a/tests/ember-data__json-api/.eslintrc.cjs b/tests/ember-data__json-api/.eslintrc.cjs new file mode 100644 index 00000000000..827dc3d3969 --- /dev/null +++ b/tests/ember-data__json-api/.eslintrc.cjs @@ -0,0 +1,39 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const diagnostic = require('@warp-drive/internal-config/eslint/diagnostic.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config({ + files: ['ember-cli-build.js', 'testem.js'], + }), + node.defaults({ + files: ['./config/environment.js', './config/targets.js'], + }), + typescript.defaults(), + diagnostic.defaults({ + files: ['tests/**/*.{js,ts}'], + }), + ], +}; diff --git a/tests/ember-data__json-api/config/environment.js b/tests/ember-data__json-api/config/environment.js index c6fbbd2b190..82ace648a37 100644 --- a/tests/ember-data__json-api/config/environment.js +++ b/tests/ember-data__json-api/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'ember-data__json-api', environment, rootURL: '/', diff --git a/tests/ember-data__json-api/ember-cli-build.js b/tests/ember-data__json-api/ember-cli-build.js index c05a1eb8e45..4a1ecce4129 100644 --- a/tests/ember-data__json-api/ember-cli-build.js +++ b/tests/ember-data__json-api/ember-cli-build.js @@ -1,11 +1,11 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { const compatWith = process.env.EMBER_DATA_FULL_COMPAT ? '99.0' : '4.12'; - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { emberData: { compatWith, }, diff --git a/tests/ember-data__json-api/package.json b/tests/ember-data__json-api/package.json index 222d8bcd64b..7e61fbc91dd 100644 --- a/tests/ember-data__json-api/package.json +++ b/tests/ember-data__json-api/package.json @@ -17,6 +17,7 @@ "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", "build:production": "pnpm build:tests -e production", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "check:types": "tsc --noEmit", "test": "bun ./diagnostic.js", "test:production": "bun ./diagnostic.js", @@ -93,6 +94,7 @@ "@glimmer/tracking": "^1.1.2", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", "@warp-drive/diagnostic": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", diff --git a/tests/ember-data__json-api/tests/integration/cache/collection-data-documents-test.ts b/tests/ember-data__json-api/tests/integration/cache/collection-data-documents-test.ts index 30fd65d2f98..3be2f677d03 100644 --- a/tests/ember-data__json-api/tests/integration/cache/collection-data-documents-test.ts +++ b/tests/ember-data__json-api/tests/integration/cache/collection-data-documents-test.ts @@ -1,17 +1,16 @@ -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; -import { module, test } from '@warp-drive/diagnostic'; - import Cache from '@ember-data/json-api'; import type Model from '@ember-data/model'; import type { StructuredDataDocument } from '@ember-data/request'; import Store from '@ember-data/store'; import type { NotificationType } from '@ember-data/store/-private/managers/notification-manager'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; -import { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; +import type { JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; +import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; +import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; import type { CollectionResourceDataDocument } from '@warp-drive/core-types/spec/document'; import type { CollectionResourceDocument } from '@warp-drive/core-types/spec/raw'; +import { module, test } from '@warp-drive/diagnostic'; type FakeRecord = { [key: string]: unknown; destroy: () => void }; class TestStore extends Store { @@ -24,7 +23,7 @@ class TestStore extends Store { const record: FakeRecord = { id, lid, type } as unknown as FakeRecord; Object.assign(record, (this.cache.peek(identifier) as JsonApiResource).attributes); - let token = this.notifications.subscribe( + const token = this.notifications.subscribe( identifier, (_: StableRecordIdentifier, kind: NotificationType, key?: string) => { if (kind === 'attributes' && key) { @@ -161,7 +160,6 @@ module('Integration | @ember-data/json-api Cache.put()', test('resources are accessible via `peek`', function (assert) { const store = new TestStore(); store.registerSchema(new TestSchema()); - debugger; const responseDocument = store.cache.put({ content: { @@ -337,9 +335,9 @@ module('Integration | @ember-data/json-api Cache.put()', assert.deepEqual(responseDocument!.data, [identifier1], 'We were given the correct data back'); - let resourceData1 = store.cache.peek(identifier1); - let resourceData2 = store.cache.peek(identifier2); - let resourceData3 = store.cache.peek(identifier3); + const resourceData1 = store.cache.peek(identifier1); + const resourceData2 = store.cache.peek(identifier2); + const resourceData3 = store.cache.peek(identifier3); assert.deepEqual( resourceData1, diff --git a/tests/ember-data__json-api/tests/integration/cache/meta-documents-test.ts b/tests/ember-data__json-api/tests/integration/cache/meta-documents-test.ts index a74aa7fab62..22a3c5a730a 100644 --- a/tests/ember-data__json-api/tests/integration/cache/meta-documents-test.ts +++ b/tests/ember-data__json-api/tests/integration/cache/meta-documents-test.ts @@ -1,15 +1,13 @@ -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; -import { module, test } from '@warp-drive/diagnostic'; - import Cache from '@ember-data/json-api'; import type { StructuredDocument } from '@ember-data/request'; import Store from '@ember-data/store'; -import { CacheOperation } from '@ember-data/store/-private/managers/notification-manager'; +import type { CacheOperation } from '@ember-data/store/-private/managers/notification-manager'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier'; -import { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; +import type { StableDocumentIdentifier, StableExistingRecordIdentifier } from '@warp-drive/core-types/identifier'; +import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; import type { CollectionResourceDataDocument, ResourceMetaDocument } from '@warp-drive/core-types/spec/document'; +import { module, test } from '@warp-drive/diagnostic'; class TestStore extends Store { override createCache(wrapper: CacheCapabilitiesManager) { diff --git a/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts b/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts index 54485617ecf..422d30ba85a 100644 --- a/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts +++ b/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts @@ -1,6 +1,3 @@ -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; -import { module, test } from '@warp-drive/diagnostic'; - import Cache from '@ember-data/json-api'; import type Model from '@ember-data/model'; import type { StructuredDocument } from '@ember-data/request'; @@ -8,11 +5,12 @@ import Store from '@ember-data/store'; import type { CacheOperation, NotificationType } from '@ember-data/store/-private/managers/notification-manager'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; import type { JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; -import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier'; +import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; +import type { StableDocumentIdentifier,StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document'; import type { SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; -import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; +import { module, test } from '@warp-drive/diagnostic'; type FakeRecord = { [key: string]: unknown; destroy: () => void }; class TestStore extends Store { @@ -25,7 +23,7 @@ class TestStore extends Store { const record: FakeRecord = { id, lid, type } as unknown as FakeRecord; Object.assign(record, (this.cache.peek(identifier) as JsonApiResource).attributes); - let token = this.notifications.subscribe( + const token = this.notifications.subscribe( identifier, (_: StableRecordIdentifier, kind: NotificationType, key?: string) => { if (kind === 'attributes' && key) { @@ -428,9 +426,9 @@ module('Integration | @ember-data/json-api Cache.put()', f assert.equal(responseDocument!.data, identifier1, 'We were given the correct data back'); - let resourceData1 = store.cache.peek(identifier1); - let resourceData2 = store.cache.peek(identifier2); - let resourceData3 = store.cache.peek(identifier3); + const resourceData1 = store.cache.peek(identifier1); + const resourceData2 = store.cache.peek(identifier2); + const resourceData3 = store.cache.peek(identifier3); assert.deepEqual( resourceData1, diff --git a/tests/ember-data__json-api/tests/integration/serialize-test.ts b/tests/ember-data__json-api/tests/integration/serialize-test.ts index 5abb0be855f..4d4ed739646 100644 --- a/tests/ember-data__json-api/tests/integration/serialize-test.ts +++ b/tests/ember-data__json-api/tests/integration/serialize-test.ts @@ -1,14 +1,13 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; -import { module, test } from '@warp-drive/diagnostic'; - import Cache from '@ember-data/json-api'; import { serializePatch, serializeResources } from '@ember-data/json-api/request'; import Store from '@ember-data/store'; import type { NotificationType } from '@ember-data/store/-private/managers/notification-manager'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; import type { JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; -import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; +import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; +import { module, test } from '@warp-drive/diagnostic'; type FakeRecord = { [key: string]: unknown; destroy: () => void }; class TestStore extends Store { @@ -21,7 +20,7 @@ class TestStore extends Store { const record: FakeRecord = { id, lid, type } as unknown as FakeRecord; Object.assign(record, (this.cache.peek(identifier) as JsonApiResource).attributes); - let token = this.notifications.subscribe( + const token = this.notifications.subscribe( identifier, (_: StableRecordIdentifier, kind: NotificationType, key?: string) => { if (kind === 'attributes' && key) { From 03140d1d10e03ffc5465649ff1837d95f52398b9 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 10:18:28 -0800 Subject: [PATCH 06/17] Add eslintrc for tests/model --- pnpm-lock.yaml | 3 ++ tests/ember-data__model/.eslintrc.cjs | 39 +++++++++++++++++++ tests/ember-data__model/config/environment.js | 2 +- tests/ember-data__model/ember-cli-build.js | 2 +- tests/ember-data__model/package.json | 2 + .../tests/integration/model-for-test.ts | 5 +-- 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 tests/ember-data__model/.eslintrc.cjs diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 942a38627fd..1ceacb498a0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3019,6 +3019,9 @@ importers: '@warp-drive/diagnostic': specifier: workspace:5.5.0-alpha.11 version: file:packages/diagnostic(@ember/test-helpers@3.2.0)(@embroider/addon-shim@1.8.7)(ember-cli-test-loader@3.1.0) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-auto-import: specifier: ^2.6.3 version: 2.6.3(webpack@5.89.0) diff --git a/tests/ember-data__model/.eslintrc.cjs b/tests/ember-data__model/.eslintrc.cjs new file mode 100644 index 00000000000..827dc3d3969 --- /dev/null +++ b/tests/ember-data__model/.eslintrc.cjs @@ -0,0 +1,39 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const diagnostic = require('@warp-drive/internal-config/eslint/diagnostic.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config({ + files: ['ember-cli-build.js', 'testem.js'], + }), + node.defaults({ + files: ['./config/environment.js', './config/targets.js'], + }), + typescript.defaults(), + diagnostic.defaults({ + files: ['tests/**/*.{js,ts}'], + }), + ], +}; diff --git a/tests/ember-data__model/config/environment.js b/tests/ember-data__model/config/environment.js index 8bbd7236b0f..8110ff7112a 100644 --- a/tests/ember-data__model/config/environment.js +++ b/tests/ember-data__model/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'ember-data__model', environment, rootURL: '/', diff --git a/tests/ember-data__model/ember-cli-build.js b/tests/ember-data__model/ember-cli-build.js index b087fcc8e2d..e145431c921 100644 --- a/tests/ember-data__model/ember-cli-build.js +++ b/tests/ember-data__model/ember-cli-build.js @@ -17,7 +17,7 @@ module.exports = function (defaults) { }), ]; - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { emberData: { compatWith, }, diff --git a/tests/ember-data__model/package.json b/tests/ember-data__model/package.json index 908053a96ae..6354a18493f 100644 --- a/tests/ember-data__model/package.json +++ b/tests/ember-data__model/package.json @@ -17,6 +17,7 @@ "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", "check:types": "tsc --noEmit", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "test": "bun ./diagnostic.js", "_syncPnpm": "bun run sync-dependencies-meta-injected" }, @@ -85,6 +86,7 @@ "@glimmer/tracking": "^1.1.2", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", "@warp-drive/diagnostic": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", diff --git a/tests/ember-data__model/tests/integration/model-for-test.ts b/tests/ember-data__model/tests/integration/model-for-test.ts index a65b72c2052..77a51cd3e02 100644 --- a/tests/ember-data__model/tests/integration/model-for-test.ts +++ b/tests/ember-data__model/tests/integration/model-for-test.ts @@ -1,8 +1,7 @@ -import { module, test } from '@warp-drive/diagnostic'; +import Store from '@ember-data/store'; import type { FieldSchema, SchemaService } from '@ember-data/store/-types/q/schema-service'; import type { RelationshipsSchema } from '@warp-drive/core-types/schema'; - -import Store from '@ember-data/store'; +import { module, test } from '@warp-drive/diagnostic'; module('modelFor without @ember-data/model', function () { test('We can call modelFor', function (assert) { From a18366bc3a83de8268870bfaaa4786f0d408288e Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 11:29:37 -0800 Subject: [PATCH 07/17] Add eslintrc for tests/request --- config/eslint/diagnostic.cjs | 23 ++++++++++++ config/eslint/node.cjs | 6 ++- config/eslint/qunit.cjs | 1 + packages/holodeck/package.json | 2 +- pnpm-lock.yaml | 3 ++ tests/builders/.eslintrc.cjs | 9 ++--- tests/docs/.eslintrc.cjs | 3 -- tests/ember-data__adapter/.eslintrc.cjs | 9 ++--- tests/ember-data__graph/.eslintrc.cjs | 9 ++--- tests/ember-data__json-api/.eslintrc.cjs | 9 ++--- tests/ember-data__model/.eslintrc.cjs | 9 ++--- tests/ember-data__request/.eslintrc.cjs | 37 +++++++++++++++++++ .../ember-data__request/config/environment.js | 2 +- tests/ember-data__request/diagnostic.js | 1 + tests/ember-data__request/ember-cli-build.js | 4 +- tests/ember-data__request/holodeck.mjs | 3 +- tests/ember-data__request/package.json | 2 + .../tests/integration/abort-test.ts | 3 +- .../tests/integration/custom-abort-test.ts | 3 +- .../integration/error-propagation-test.ts | 4 +- .../tests/integration/fetch-handler-test.ts | 5 +-- .../integration/graceful-dev-errors-test.ts | 9 ++--- .../graceful-dev-handler-errors-test.ts | 9 ++--- .../tests/integration/immutability-test.ts | 4 +- .../integration/response-currying-test.ts | 3 +- .../tests/integration/response-test.ts | 3 +- .../tests/integration/service-test.ts | 8 ++-- .../tests/integration/setup-test.ts | 3 +- .../integration/stateful-handler-test.ts | 8 ++-- .../tests/integration/streams-test.ts | 3 +- tests/warp-drive__schema-record/.eslintrc.cjs | 8 +--- 31 files changed, 120 insertions(+), 85 deletions(-) create mode 100644 tests/ember-data__request/.eslintrc.cjs diff --git a/config/eslint/diagnostic.cjs b/config/eslint/diagnostic.cjs index 3441ad18777..5f4b967ca59 100644 --- a/config/eslint/diagnostic.cjs +++ b/config/eslint/diagnostic.cjs @@ -14,6 +14,7 @@ function defaults(config = {}) { { 'qunit/require-expect': 'off', 'qunit/no-assert-equal': 'off', + 'qunit/no-assert-logical-expression': 'off', 'qunit/no-conditional-assertions': 'off', 'qunit/no-ok-equality': 'off', } @@ -21,6 +22,28 @@ function defaults(config = {}) { }; } +function config() { + return { + files: ['./diagnostic.js'], + parserOptions: { + sourceType: 'module', + ecmaVersion: 2022, + }, + env: { + browser: false, + node: true, + es6: true, + }, + plugins: ['n'], + extends: 'plugin:n/recommended', + rules: { + // It's ok to use unpublished files here since we don't ship these + 'n/no-unpublished-require': 'off', + }, + }; +} + module.exports = { + config, defaults, }; diff --git a/config/eslint/node.cjs b/config/eslint/node.cjs index 813097218bf..daf752d7fc7 100644 --- a/config/eslint/node.cjs +++ b/config/eslint/node.cjs @@ -1,6 +1,8 @@ function defaults(config) { const result = { - files: !config?.useModules ? ['./index.js', './addon-main.cjs', './addon-main.js'] : [], + files: !config?.useModules + ? ['./index.js', './addon-main.cjs', './addon-main.js', './config/environment.js', './config/targets.js'] + : [], parserOptions: { sourceType: config?.useModules ? 'module' : 'script', ecmaVersion: 2022, @@ -25,7 +27,7 @@ function defaults(config) { function config(config) { const result = { - files: ['./babel.config.js', './.eslintrc.cjs', './rollup.config.mjs'], + files: ['./.eslintrc.cjs', './babel.config.js', './ember-cli-build.js', './rollup.config.mjs', './testem.js'], parserOptions: { sourceType: config?.useModules ? 'module' : 'script', ecmaVersion: 2022, diff --git a/config/eslint/qunit.cjs b/config/eslint/qunit.cjs index a1dd577b34a..0f9207f6843 100644 --- a/config/eslint/qunit.cjs +++ b/config/eslint/qunit.cjs @@ -16,6 +16,7 @@ function defaults(config = {}) { }), config?.rules, { + 'qunit/no-assert-logical-expression': 'off', 'qunit/no-conditional-assertions': 'off', 'qunit/no-ok-equality': 'off', } diff --git a/packages/holodeck/package.json b/packages/holodeck/package.json index bbdb1123736..8492b81ca4f 100644 --- a/packages/holodeck/package.json +++ b/packages/holodeck/package.json @@ -41,7 +41,7 @@ "holodeck": "./bin/holodeck.js" }, "scripts": { - "build:types": "tsc --build", + "build:types": "tsc --build --force", "build:client": "rollup --config", "_build": "bun run build:client && bun run build:types", "start": "rollup --config --watch", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1ceacb498a0..396010b1301 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3145,6 +3145,9 @@ importers: '@warp-drive/holodeck': specifier: workspace:5.5.0-alpha.11 version: file:packages/holodeck(@ember-data/request@5.5.0-alpha.11)(@warp-drive/core-types@5.5.0-alpha.11) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config bun-types: specifier: ^1.0.11 version: 1.0.11 diff --git a/tests/builders/.eslintrc.cjs b/tests/builders/.eslintrc.cjs index 827dc3d3969..b8f1386c9b7 100644 --- a/tests/builders/.eslintrc.cjs +++ b/tests/builders/.eslintrc.cjs @@ -25,13 +25,10 @@ module.exports = { ignorePatterns: ignore.ignoreRules(), overrides: [ - node.config({ - files: ['ember-cli-build.js', 'testem.js'], - }), - node.defaults({ - files: ['./config/environment.js', './config/targets.js'], - }), + node.config(), + node.defaults(), typescript.defaults(), + diagnostic.config(), diagnostic.defaults({ files: ['tests/**/*.{js,ts}'], }), diff --git a/tests/docs/.eslintrc.cjs b/tests/docs/.eslintrc.cjs index b0bcb214e41..d46717879cc 100644 --- a/tests/docs/.eslintrc.cjs +++ b/tests/docs/.eslintrc.cjs @@ -31,9 +31,6 @@ module.exports = { }), qunit.defaults({ files: ['index.{js,ts}'], - rules: { - 'qunit/no-assert-logical-expression': 'off', - }, }), ], }; diff --git a/tests/ember-data__adapter/.eslintrc.cjs b/tests/ember-data__adapter/.eslintrc.cjs index 685245dd9cd..3074b042bde 100644 --- a/tests/ember-data__adapter/.eslintrc.cjs +++ b/tests/ember-data__adapter/.eslintrc.cjs @@ -25,13 +25,10 @@ module.exports = { ignorePatterns: ignore.ignoreRules(), overrides: [ - node.config({ - files: ['ember-cli-build.js', 'testem.js'], - }), - node.defaults({ - files: ['./config/environment.js', './config/targets.js'], - }), + node.config(), + node.defaults(), typescript.defaults(), + diagnostic.config(), diagnostic.defaults({ files: ['tests/**/*.{js,ts}'], allowedImports: ['@ember/object'], diff --git a/tests/ember-data__graph/.eslintrc.cjs b/tests/ember-data__graph/.eslintrc.cjs index 827dc3d3969..b8f1386c9b7 100644 --- a/tests/ember-data__graph/.eslintrc.cjs +++ b/tests/ember-data__graph/.eslintrc.cjs @@ -25,13 +25,10 @@ module.exports = { ignorePatterns: ignore.ignoreRules(), overrides: [ - node.config({ - files: ['ember-cli-build.js', 'testem.js'], - }), - node.defaults({ - files: ['./config/environment.js', './config/targets.js'], - }), + node.config(), + node.defaults(), typescript.defaults(), + diagnostic.config(), diagnostic.defaults({ files: ['tests/**/*.{js,ts}'], }), diff --git a/tests/ember-data__json-api/.eslintrc.cjs b/tests/ember-data__json-api/.eslintrc.cjs index 827dc3d3969..b8f1386c9b7 100644 --- a/tests/ember-data__json-api/.eslintrc.cjs +++ b/tests/ember-data__json-api/.eslintrc.cjs @@ -25,13 +25,10 @@ module.exports = { ignorePatterns: ignore.ignoreRules(), overrides: [ - node.config({ - files: ['ember-cli-build.js', 'testem.js'], - }), - node.defaults({ - files: ['./config/environment.js', './config/targets.js'], - }), + node.config(), + node.defaults(), typescript.defaults(), + diagnostic.config(), diagnostic.defaults({ files: ['tests/**/*.{js,ts}'], }), diff --git a/tests/ember-data__model/.eslintrc.cjs b/tests/ember-data__model/.eslintrc.cjs index 827dc3d3969..b8f1386c9b7 100644 --- a/tests/ember-data__model/.eslintrc.cjs +++ b/tests/ember-data__model/.eslintrc.cjs @@ -25,13 +25,10 @@ module.exports = { ignorePatterns: ignore.ignoreRules(), overrides: [ - node.config({ - files: ['ember-cli-build.js', 'testem.js'], - }), - node.defaults({ - files: ['./config/environment.js', './config/targets.js'], - }), + node.config(), + node.defaults(), typescript.defaults(), + diagnostic.config(), diagnostic.defaults({ files: ['tests/**/*.{js,ts}'], }), diff --git a/tests/ember-data__request/.eslintrc.cjs b/tests/ember-data__request/.eslintrc.cjs new file mode 100644 index 00000000000..df6dbd72caa --- /dev/null +++ b/tests/ember-data__request/.eslintrc.cjs @@ -0,0 +1,37 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const diagnostic = require('@warp-drive/internal-config/eslint/diagnostic.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults(), + typescript.defaults(), + diagnostic.config(), + diagnostic.defaults({ + files: ['tests/**/*.{js,ts}'], + allowedImports: ['@ember/application', '@ember/owner', '@ember/service'], + }), + ], +}; diff --git a/tests/ember-data__request/config/environment.js b/tests/ember-data__request/config/environment.js index 6af2e8fe9b5..98be18b2f4f 100644 --- a/tests/ember-data__request/config/environment.js +++ b/tests/ember-data__request/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'ember-data__request', environment, rootURL: '/', diff --git a/tests/ember-data__request/diagnostic.js b/tests/ember-data__request/diagnostic.js index b207883e528..75db4662ade 100644 --- a/tests/ember-data__request/diagnostic.js +++ b/tests/ember-data__request/diagnostic.js @@ -1,4 +1,5 @@ /* global Bun */ +// eslint-disable-next-line n/no-missing-import, n/no-unpublished-import import launch from '@warp-drive/diagnostic/server/default-setup.js'; /** @type {import('bun-types')} */ diff --git a/tests/ember-data__request/ember-cli-build.js b/tests/ember-data__request/ember-cli-build.js index 36cec92dcc8..6a145f21adb 100644 --- a/tests/ember-data__request/ember-cli-build.js +++ b/tests/ember-data__request/ember-cli-build.js @@ -1,11 +1,11 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { const compatWith = process.env.EMBER_DATA_FULL_COMPAT ? '99.0' : null; - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { emberData: { compatWith, }, diff --git a/tests/ember-data__request/holodeck.mjs b/tests/ember-data__request/holodeck.mjs index 9f9784e0dd7..610871e25dc 100644 --- a/tests/ember-data__request/holodeck.mjs +++ b/tests/ember-data__request/holodeck.mjs @@ -1,7 +1,8 @@ -import { createServer } from '@warp-drive/holodeck'; import { dirname } from 'node:path'; import { fileURLToPath } from 'url'; +import { createServer } from '@warp-drive/holodeck'; + const __dirname = dirname(fileURLToPath(import.meta.url)); export default createServer({ diff --git a/tests/ember-data__request/package.json b/tests/ember-data__request/package.json index 25309c0e7f0..b66113c14e3 100644 --- a/tests/ember-data__request/package.json +++ b/tests/ember-data__request/package.json @@ -16,6 +16,7 @@ "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", "_build:production": "pnpm build:tests -e production", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "check:types": "tsc --noEmit", "test": "bun ./diagnostic.js", "_test:production": "bun ./diagnostic.js", @@ -59,6 +60,7 @@ "@warp-drive/core-types": "workspace:5.5.0-alpha.11", "@warp-drive/diagnostic": "workspace:5.5.0-alpha.11", "@warp-drive/holodeck": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "bun-types": "^1.0.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", diff --git a/tests/ember-data__request/tests/integration/abort-test.ts b/tests/ember-data__request/tests/integration/abort-test.ts index 5ec5717697b..24f2122618a 100644 --- a/tests/ember-data__request/tests/integration/abort-test.ts +++ b/tests/ember-data__request/tests/integration/abort-test.ts @@ -1,9 +1,8 @@ -import { module, test } from '@warp-drive/diagnostic'; - import type { RequestInfo } from '@ember-data/request'; import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Future, Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; module('RequestManager | Abort', function () { test('We can abort requests', async function (assert) { diff --git a/tests/ember-data__request/tests/integration/custom-abort-test.ts b/tests/ember-data__request/tests/integration/custom-abort-test.ts index 56a2ee5a071..4f724fc2092 100644 --- a/tests/ember-data__request/tests/integration/custom-abort-test.ts +++ b/tests/ember-data__request/tests/integration/custom-abort-test.ts @@ -1,9 +1,8 @@ -import { module, test } from '@warp-drive/diagnostic'; - import type { RequestInfo } from '@ember-data/request'; import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Future, Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; module('RequestManager | Custom Abort', function () { test('We can abort requests', async function (assert) { diff --git a/tests/ember-data__request/tests/integration/error-propagation-test.ts b/tests/ember-data__request/tests/integration/error-propagation-test.ts index 035fb104504..d81421b2801 100644 --- a/tests/ember-data__request/tests/integration/error-propagation-test.ts +++ b/tests/ember-data__request/tests/integration/error-propagation-test.ts @@ -1,9 +1,8 @@ -import { module, test } from '@warp-drive/diagnostic'; - import type { StructuredErrorDocument } from '@ember-data/request'; import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Future, Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; function isErrorDoc(e: Error | unknown | StructuredErrorDocument): e is StructuredErrorDocument { return Boolean(e && e instanceof Error && 'request' in e); @@ -18,6 +17,7 @@ module('RequestManager | Error Propagation', function () { assert.ok(true, 'catching handler triggered'); try { // await to catch, else error is curried + // eslint-disable-next-line qunit/no-early-return return await next(context.request); } catch (e) { assert.equal((e as Error).message, 'Oops!', 'We caught the error'); diff --git a/tests/ember-data__request/tests/integration/fetch-handler-test.ts b/tests/ember-data__request/tests/integration/fetch-handler-test.ts index 40e3050a62b..2345590a047 100644 --- a/tests/ember-data__request/tests/integration/fetch-handler-test.ts +++ b/tests/ember-data__request/tests/integration/fetch-handler-test.ts @@ -1,10 +1,9 @@ +import RequestManager from '@ember-data/request'; +import Fetch from '@ember-data/request/fetch'; import { module, test } from '@warp-drive/diagnostic'; import { mock, MockServerHandler } from '@warp-drive/holodeck'; import { GET } from '@warp-drive/holodeck/mock'; -import RequestManager from '@ember-data/request'; -import Fetch from '@ember-data/request/fetch'; - function isNetworkError(e: unknown): asserts e is Error & { status: number; statusText: string; diff --git a/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts b/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts index 2cc4b98ab98..dda974854c0 100644 --- a/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts +++ b/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts @@ -1,12 +1,11 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ - -import { module, test } from '@warp-drive/diagnostic'; + + + import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; module('RequestManager | Graceful Errors', function () { test('We error meaningfully for `.use()`', function (assert) { diff --git a/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts b/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts index 0fa08056fca..f5891dac324 100644 --- a/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts +++ b/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts @@ -1,12 +1,11 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ - -import { module, test } from '@warp-drive/diagnostic'; + + + import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; module('RequestManager | Graceful Handler Errors', function () { test('We error meaningfully for empty requests', async function (assert) { diff --git a/tests/ember-data__request/tests/integration/immutability-test.ts b/tests/ember-data__request/tests/integration/immutability-test.ts index 0ed3cac24fd..547607f181b 100644 --- a/tests/ember-data__request/tests/integration/immutability-test.ts +++ b/tests/ember-data__request/tests/integration/immutability-test.ts @@ -1,8 +1,7 @@ -import { module, test } from '@warp-drive/diagnostic'; - import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; module('RequestManager | Immutability', function () { test('RequestInfo passed to a handler is Immutable', async function (assert) { @@ -55,6 +54,7 @@ module('RequestManager | Immutability', function () { const headers = new Headers(context.request.headers); headers.append('house', 'home'); // @ts-expect-error Types are wrong: Property 'entries' does not exist on type 'Headers'. + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call return Promise.resolve([...headers.entries()] as T); }, }; diff --git a/tests/ember-data__request/tests/integration/response-currying-test.ts b/tests/ember-data__request/tests/integration/response-currying-test.ts index 69267236137..47ed8f52c27 100644 --- a/tests/ember-data__request/tests/integration/response-currying-test.ts +++ b/tests/ember-data__request/tests/integration/response-currying-test.ts @@ -1,8 +1,7 @@ -import { module, test } from '@warp-drive/diagnostic'; - import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; const IGNORED_HEADERS = new Set(['connection', 'keep-alive', 'content-length', 'date', 'etag', 'last-modified']); diff --git a/tests/ember-data__request/tests/integration/response-test.ts b/tests/ember-data__request/tests/integration/response-test.ts index d98b7617f34..3291e1fe01b 100644 --- a/tests/ember-data__request/tests/integration/response-test.ts +++ b/tests/ember-data__request/tests/integration/response-test.ts @@ -1,8 +1,7 @@ -import { module, test } from '@warp-drive/diagnostic'; - import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; const IGNORED_HEADERS = new Set(['connection', 'keep-alive', 'content-length', 'date', 'etag', 'last-modified']); diff --git a/tests/ember-data__request/tests/integration/service-test.ts b/tests/ember-data__request/tests/integration/service-test.ts index c08ededeebe..2a50290d42e 100644 --- a/tests/ember-data__request/tests/integration/service-test.ts +++ b/tests/ember-data__request/tests/integration/service-test.ts @@ -1,14 +1,12 @@ import { getOwner } from '@ember/application'; import Service, { inject as service } from '@ember/service'; - -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import Resolver from 'ember-resolver'; import RequestManager from '@ember-data/request'; - -import { TestContext } from '@ember/test-helpers'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; module('RequestManager | Ember Service Setup', function (hooks) { setupTest(hooks, { resolver: new Resolver() }); diff --git a/tests/ember-data__request/tests/integration/setup-test.ts b/tests/ember-data__request/tests/integration/setup-test.ts index 6f1784aced4..03dca9f8600 100644 --- a/tests/ember-data__request/tests/integration/setup-test.ts +++ b/tests/ember-data__request/tests/integration/setup-test.ts @@ -1,8 +1,7 @@ -import { module, test } from '@warp-drive/diagnostic'; - import RequestManager from '@ember-data/request'; import type { Context as HandlerRequestContext } from '@ember-data/request/-private/context'; import type { NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; module('RequestManager | Basic Setup', function () { test('We can call new RequestManager() with no args', function (assert) { diff --git a/tests/ember-data__request/tests/integration/stateful-handler-test.ts b/tests/ember-data__request/tests/integration/stateful-handler-test.ts index 4faf8c31bed..1a8c1a1897f 100644 --- a/tests/ember-data__request/tests/integration/stateful-handler-test.ts +++ b/tests/ember-data__request/tests/integration/stateful-handler-test.ts @@ -1,16 +1,14 @@ import { setOwner } from '@ember/owner'; import { service } from '@ember/service'; - -import { TestContext } from '@ember/test-helpers'; - -import { module, test } from '@warp-drive/diagnostic'; -import { setupTest } from '@warp-drive/diagnostic/ember'; +import type { TestContext } from '@ember/test-helpers'; import Resolver from 'ember-resolver'; import RequestManager from '@ember-data/request'; import type { Context as HandlerRequestContext } from '@ember-data/request/-private/context'; import type { NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; +import { setupTest } from '@warp-drive/diagnostic/ember'; module('RequestManager | Stateful Handlers', function (hooks) { setupTest(hooks, { resolver: new Resolver() }); diff --git a/tests/ember-data__request/tests/integration/streams-test.ts b/tests/ember-data__request/tests/integration/streams-test.ts index ce622a99585..654772e9139 100644 --- a/tests/ember-data__request/tests/integration/streams-test.ts +++ b/tests/ember-data__request/tests/integration/streams-test.ts @@ -1,8 +1,7 @@ -import { module, test } from '@warp-drive/diagnostic'; - import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Future, Handler, NextFn } from '@ember-data/request/-private/types'; +import { module, test } from '@warp-drive/diagnostic'; module('RequestManager | Streams', function () { test('We can read the stream returned from a handler', async function (assert) { diff --git a/tests/warp-drive__schema-record/.eslintrc.cjs b/tests/warp-drive__schema-record/.eslintrc.cjs index c2750b82c80..d6e11b177dc 100644 --- a/tests/warp-drive__schema-record/.eslintrc.cjs +++ b/tests/warp-drive__schema-record/.eslintrc.cjs @@ -25,12 +25,8 @@ module.exports = { ignorePatterns: ignore.ignoreRules(), overrides: [ - node.config({ - files: ['ember-cli-build.js', 'testem.js'], - }), - node.defaults({ - files: ['./config/environment.js', './config/targets.js'], - }), + node.config(), + node.defaults(), typescript.defaults(), qunit.defaults({ files: ['tests/**/*.{js,ts}'], From 048983c469462233e200c2f5e10614df7cab58cd Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 11:34:33 -0800 Subject: [PATCH 08/17] Add eslintrc for tests/serializer --- pnpm-lock.yaml | 3 ++ tests/ember-data__serializer/.eslintrc.cjs | 36 +++++++++++++++++++ .../app/services/store.ts | 5 ++- .../config/environment.js | 2 +- .../ember-data__serializer/ember-cli-build.js | 2 +- tests/ember-data__serializer/package.json | 4 +-- tests/ember-data__serializer/testem.js | 2 +- .../tests/integration/create-record-test.js | 4 +-- .../tests/integration/delete-record-test.js | 12 +++---- .../tests/integration/errors-test.js | 6 ++-- .../tests/integration/normalize-test.js | 2 +- .../tests/integration/push-payload-test.js | 2 +- .../tests/integration/relationships-test.js | 12 +++---- .../tests/integration/requests-test.js | 8 ++--- .../tests/integration/serialize-test.js | 12 +++---- .../tests/integration/update-record-test.js | 8 ++--- 16 files changed, 79 insertions(+), 41 deletions(-) create mode 100644 tests/ember-data__serializer/.eslintrc.cjs diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 396010b1301..04880f1336f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3293,6 +3293,9 @@ importers: '@warp-drive/core-types': specifier: workspace:5.5.0-alpha.11 version: file:packages/core-types(@babel/core@7.23.3) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-auto-import: specifier: ^2.6.3 version: 2.6.3(webpack@5.89.0) diff --git a/tests/ember-data__serializer/.eslintrc.cjs b/tests/ember-data__serializer/.eslintrc.cjs new file mode 100644 index 00000000000..df0739f45fe --- /dev/null +++ b/tests/ember-data__serializer/.eslintrc.cjs @@ -0,0 +1,36 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const qunit = require('@warp-drive/internal-config/eslint/qunit.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults(), + typescript.defaults(), + qunit.defaults({ + files: ['tests/**/*.{js,ts}'], + allowedImports: ['@ember/object'], + }), + ], +}; diff --git a/tests/ember-data__serializer/app/services/store.ts b/tests/ember-data__serializer/app/services/store.ts index 33a046b1899..3a52705a78e 100644 --- a/tests/ember-data__serializer/app/services/store.ts +++ b/tests/ember-data__serializer/app/services/store.ts @@ -1,5 +1,3 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; - import JSONAPICache from '@ember-data/json-api'; import { adapterFor, @@ -16,7 +14,8 @@ import RequestManager from '@ember-data/request'; import Fetch from '@ember-data/request/fetch'; import BaseStore, { CacheHandler } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; -import { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { ModelSchema } from '@ember-data/store/-types/q/ds-model'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; export default class Store extends BaseStore { constructor(args: unknown) { diff --git a/tests/ember-data__serializer/config/environment.js b/tests/ember-data__serializer/config/environment.js index 9c254400d34..58f9db99cf0 100644 --- a/tests/ember-data__serializer/config/environment.js +++ b/tests/ember-data__serializer/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'ember-data__serializer', environment, rootURL: '/', diff --git a/tests/ember-data__serializer/ember-cli-build.js b/tests/ember-data__serializer/ember-cli-build.js index 76f3d28dcf9..bd6a82673e4 100644 --- a/tests/ember-data__serializer/ember-cli-build.js +++ b/tests/ember-data__serializer/ember-cli-build.js @@ -5,7 +5,7 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { // Add options here 'ember-cli-babel': { diff --git a/tests/ember-data__serializer/package.json b/tests/ember-data__serializer/package.json index 44018edaced..81d02b734d9 100644 --- a/tests/ember-data__serializer/package.json +++ b/tests/ember-data__serializer/package.json @@ -16,8 +16,7 @@ }, "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", - "lint:hbs": "ember-template-lint .", - "lint:old": "eslint --config ../../.eslintrc.js --ignore-path ../../.eslintignore .", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "check:types": "tsc --noEmit", "start": "ember serve", "test": "ember test --test-port=0 --path=dist-test", @@ -87,6 +86,7 @@ "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", diff --git a/tests/ember-data__serializer/testem.js b/tests/ember-data__serializer/testem.js index fb97c3f065e..2d19b92e408 100644 --- a/tests/ember-data__serializer/testem.js +++ b/tests/ember-data__serializer/testem.js @@ -1,4 +1,4 @@ -// eslint-disable-next-line n/no-unpublished-require + const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console diff --git a/tests/ember-data__serializer/tests/integration/create-record-test.js b/tests/ember-data__serializer/tests/integration/create-record-test.js index c9bda01d0b0..2016df7797c 100644 --- a/tests/ember-data__serializer/tests/integration/create-record-test.js +++ b/tests/ember-data__serializer/tests/integration/create-record-test.js @@ -94,7 +94,7 @@ module('Serializer Contract | running createRecord with minimum serializer', fun const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: '1', firstName: 'John', lastName: 'Smith', @@ -191,7 +191,7 @@ module('Serializer Contract | running createRecord with minimum serializer', fun const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: '1', firstName: 'John', lastName: 'Smith', diff --git a/tests/ember-data__serializer/tests/integration/delete-record-test.js b/tests/ember-data__serializer/tests/integration/delete-record-test.js index b23e108d48e..35d16dd248f 100644 --- a/tests/ember-data__serializer/tests/integration/delete-record-test.js +++ b/tests/ember-data__serializer/tests/integration/delete-record-test.js @@ -39,7 +39,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun test('save after deleting record does not call normalizeResponse and serialize', async function (assert) { let normalizeResponseCalled = 0; - let _payloads = [ + const _payloads = [ { id: '1', type: 'person', @@ -87,7 +87,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun const store = this.owner.lookup('service:store'); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); assert.deepEqual(person.toJSON(), { id: '1', @@ -108,7 +108,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun let serializeCalled = 0; let serializeIntoHashCalled = 0; let normalizeResponseCalled = 0; - let _payloads = [ + const _payloads = [ { id: '1', type: 'person', @@ -164,7 +164,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun const store = this.owner.lookup('service:store'); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); assert.deepEqual(person.toJSON(), { id: '1', @@ -185,7 +185,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun test('save after deleting record does call normalizeResponse if response provided', async function (assert) { let normalizeResponseCalled = 0; - let _payloads = [ + const _payloads = [ { id: '1', type: 'person', @@ -228,7 +228,7 @@ module('Serializer Contract | running deleteRecord with minimum serializer', fun const store = this.owner.lookup('service:store'); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); assert.deepEqual(person.toJSON(), { id: '1', diff --git a/tests/ember-data__serializer/tests/integration/errors-test.js b/tests/ember-data__serializer/tests/integration/errors-test.js index 6b32d430a12..d949ef61808 100644 --- a/tests/ember-data__serializer/tests/integration/errors-test.js +++ b/tests/ember-data__serializer/tests/integration/errors-test.js @@ -49,7 +49,7 @@ module( } this.owner.register('adapter:application', TestAdapter); - let store = this.owner.lookup('service:Store'); + const store = this.owner.lookup('service:Store'); let errors; try { await store.findRecord('person', 1); @@ -84,8 +84,8 @@ module( } this.owner.register('adapter:application', TestAdapter); - let store = this.owner.lookup('service:Store'); - let person = store.createRecord('person', {}); + const store = this.owner.lookup('service:Store'); + const person = store.createRecord('person', {}); let errors; try { await person.save(); diff --git a/tests/ember-data__serializer/tests/integration/normalize-test.js b/tests/ember-data__serializer/tests/integration/normalize-test.js index 724d51216e2..2b6c2469b7a 100644 --- a/tests/ember-data__serializer/tests/integration/normalize-test.js +++ b/tests/ember-data__serializer/tests/integration/normalize-test.js @@ -54,7 +54,7 @@ module('Serializer Contract | normalize method forwards to Serializer#normalize' const store = this.owner.lookup('service:store'); - let payload = store.normalize('person', { + const payload = store.normalize('person', { id: '1', type: 'person', attributes: { diff --git a/tests/ember-data__serializer/tests/integration/push-payload-test.js b/tests/ember-data__serializer/tests/integration/push-payload-test.js index 59444b51569..c870217c331 100644 --- a/tests/ember-data__serializer/tests/integration/push-payload-test.js +++ b/tests/ember-data__serializer/tests/integration/push-payload-test.js @@ -70,7 +70,7 @@ module('Serializer Contract | pushPayload method forwards to Serializer#pushPayl lastName: 'Smith', }, }); - let person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); assert.strictEqual(pushPayloadCalled, 1, 'pushPayload called once'); assert.deepEqual( diff --git a/tests/ember-data__serializer/tests/integration/relationships-test.js b/tests/ember-data__serializer/tests/integration/relationships-test.js index e5295957534..6fb05e64f19 100644 --- a/tests/ember-data__serializer/tests/integration/relationships-test.js +++ b/tests/ember-data__serializer/tests/integration/relationships-test.js @@ -90,7 +90,7 @@ module('Serializer Contract | running requests for async relationships with mini const store = this.owner.lookup('service:store'); - let post = store.push({ + const post = store.push({ data: { id: '1', type: 'post', @@ -113,7 +113,7 @@ module('Serializer Contract | running requests for async relationships with mini }, }, }); - let comments = await post.comments; + const comments = await post.comments; assert.strictEqual(normalizeResponseCalled, 1, 'normalizeResponse is called once'); assert.deepEqual( @@ -164,7 +164,7 @@ module('Serializer Contract | running requests for async relationships with mini const store = this.owner.lookup('service:store'); - let post = store.push({ + const post = store.push({ data: { id: '1', type: 'post', @@ -180,7 +180,7 @@ module('Serializer Contract | running requests for async relationships with mini }, }, }); - let comments = await post.comments; + const comments = await post.comments; assert.strictEqual(normalizeResponseCalled, 1, 'normalizeResponse is called once'); assert.deepEqual( @@ -238,7 +238,7 @@ module('Serializer Contract | running requests for async relationships with mini const store = this.owner.lookup('service:store'); - let comment = store.push({ + const comment = store.push({ data: { id: '1', type: 'comment', @@ -254,7 +254,7 @@ module('Serializer Contract | running requests for async relationships with mini }, }, }); - let post = await comment.post; + const post = await comment.post; assert.strictEqual(normalizeResponseCalled, 1, 'normalizeResponse is called once'); assert.deepEqual(post.title, 'Chris', 'response is expected response'); diff --git a/tests/ember-data__serializer/tests/integration/requests-test.js b/tests/ember-data__serializer/tests/integration/requests-test.js index 6bb0d49e1d1..bb6dd16ac5d 100644 --- a/tests/ember-data__serializer/tests/integration/requests-test.js +++ b/tests/ember-data__serializer/tests/integration/requests-test.js @@ -53,7 +53,7 @@ module('Serializer Contract | running requests with minimum serializer', functio const store = this.owner.lookup('service:store'); - let response = await store.findAll('person'); + const response = await store.findAll('person'); assert.strictEqual(normalizeResponseCalled, 1, 'normalizeResponse is called once'); assert.deepEqual( @@ -109,7 +109,7 @@ module('Serializer Contract | running requests with minimum serializer', functio const store = this.owner.lookup('service:store'); - let response = await store.findRecord('person', 'urn:person:1'); + const response = await store.findRecord('person', 'urn:person:1'); assert.strictEqual(normalizeResponseCalled, 1, 'normalizeResponse is called once'); assert.deepEqual(response.name, 'John', 'response is expected response'); @@ -147,7 +147,7 @@ module('Serializer Contract | running requests with minimum serializer', functio const store = this.owner.lookup('service:store'); - let response = await store.query('person', { name: 'Chris' }); + const response = await store.query('person', { name: 'Chris' }); assert.strictEqual(normalizeResponseCalled, 1, 'normalizeResponse is called once'); assert.deepEqual( @@ -203,7 +203,7 @@ module('Serializer Contract | running requests with minimum serializer', functio const store = this.owner.lookup('service:store'); - let response = await store.queryRecord('person', { name: 'Chris' }); + const response = await store.queryRecord('person', { name: 'Chris' }); assert.strictEqual(normalizeResponseCalled, 1, 'normalizeResponse is called once'); assert.deepEqual(response.name, 'John', 'response is expected response'); diff --git a/tests/ember-data__serializer/tests/integration/serialize-test.js b/tests/ember-data__serializer/tests/integration/serialize-test.js index dcde3d63fa7..6a2fd6080f0 100644 --- a/tests/ember-data__serializer/tests/integration/serialize-test.js +++ b/tests/ember-data__serializer/tests/integration/serialize-test.js @@ -63,7 +63,7 @@ module('Serializer Contract | serialize methods forward to Serializer#serialize' const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: '1', firstName: 'John', lastName: 'Smith', @@ -78,7 +78,7 @@ module('Serializer Contract | serialize methods forward to Serializer#serialize' }, }); - let serializedPerson = person.serialize(); + const serializedPerson = person.serialize(); assert.strictEqual(serializeCalled, 1, 'serialize called once'); assert.deepEqual(serializedPerson, { @@ -118,7 +118,7 @@ module('Serializer Contract | serialize methods forward to Serializer#serialize' const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: '1', firstName: 'John', lastName: 'Smith', @@ -133,7 +133,7 @@ module('Serializer Contract | serialize methods forward to Serializer#serialize' }, }); - let serializedPerson = person._createSnapshot().serialize(); + const serializedPerson = person._createSnapshot().serialize(); assert.strictEqual(serializeCalled, 1, 'serialize called once'); assert.deepEqual(serializedPerson, { @@ -173,7 +173,7 @@ module('Serializer Contract | serialize methods forward to Serializer#serialize' const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: '1', firstName: 'John', lastName: 'Smith', @@ -188,7 +188,7 @@ module('Serializer Contract | serialize methods forward to Serializer#serialize' }, }); - let serializedPerson = store.serializeRecord(person); + const serializedPerson = store.serializeRecord(person); assert.strictEqual(serializeCalled, 1, 'serialize called once'); assert.deepEqual(serializedPerson, { diff --git a/tests/ember-data__serializer/tests/integration/update-record-test.js b/tests/ember-data__serializer/tests/integration/update-record-test.js index d96bc9bf55b..d03e41f36c4 100644 --- a/tests/ember-data__serializer/tests/integration/update-record-test.js +++ b/tests/ember-data__serializer/tests/integration/update-record-test.js @@ -40,7 +40,7 @@ module('Serializer Contract | running createRecord [update] with minimum seriali test('save after mutating record calls normalizeResponse and serialize', async function (assert) { let serializeCalled = 0; let normalizeResponseCalled = 0; - let _payloads = [ + const _payloads = [ { id: '1', type: 'person', @@ -104,7 +104,7 @@ module('Serializer Contract | running createRecord [update] with minimum seriali const store = this.owner.lookup('service:store'); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); assert.deepEqual(person.toJSON(), { id: '1', @@ -137,7 +137,7 @@ module('Serializer Contract | running createRecord [update] with minimum seriali let serializeIntoHashCalled = 0; let normalizeResponseCalled = 0; - let _payloads = [ + const _payloads = [ { id: '1', type: 'person', @@ -207,7 +207,7 @@ module('Serializer Contract | running createRecord [update] with minimum seriali const store = this.owner.lookup('service:store'); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); assert.deepEqual(person.toJSON(), { id: '1', From b3785ff446579bd1ed597bd7079e1e330bf0ec0c Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 12:33:07 -0800 Subject: [PATCH 09/17] Add tsconfig and eslintrc for tests/embroider-basic-compat --- pnpm-lock.yaml | 5 ++- tests/embroider-basic-compat/.eslintrc.cjs | 43 +++++++++++++++++++ .../app/adapters/application.ts | 2 + .../embroider-basic-compat/app/models/user.ts | 1 + .../config/environment.js | 2 +- .../embroider-basic-compat/ember-cli-build.js | 2 +- tests/embroider-basic-compat/package.json | 7 +-- tests/embroider-basic-compat/testem.js | 2 +- tests/embroider-basic-compat/tsconfig.json | 30 +++++++++++++ 9 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/embroider-basic-compat/.eslintrc.cjs create mode 100644 tests/embroider-basic-compat/tsconfig.json diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04880f1336f..42a144f24b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3428,6 +3428,9 @@ importers: '@glimmer/tracking': specifier: ^1.1.2 version: 1.1.2 + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-cli: specifier: ~5.4.0 version: 5.4.0 @@ -3477,7 +3480,7 @@ importers: specifier: ^3.0.0 version: 3.0.0 typescript: - specifier: ~5.2.2 + specifier: ^5.2.2 version: 5.2.2 dependenciesMeta: '@ember-data/unpublished-test-infra': diff --git a/tests/embroider-basic-compat/.eslintrc.cjs b/tests/embroider-basic-compat/.eslintrc.cjs new file mode 100644 index 00000000000..9d47a37caab --- /dev/null +++ b/tests/embroider-basic-compat/.eslintrc.cjs @@ -0,0 +1,43 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const qunit = require('@warp-drive/internal-config/eslint/qunit.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults(), + typescript.defaults({ + rules: { + // TODO: Enable these once we get types working properly + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + }, + }), + qunit.defaults({ + files: ['tests/**/*.{js,ts}'], + allowedImports: [], + }), + ], +}; diff --git a/tests/embroider-basic-compat/app/adapters/application.ts b/tests/embroider-basic-compat/app/adapters/application.ts index 091f5ab1225..f88acbac13d 100644 --- a/tests/embroider-basic-compat/app/adapters/application.ts +++ b/tests/embroider-basic-compat/app/adapters/application.ts @@ -1,4 +1,6 @@ +// @ts-expect-error import RESTAdapter from '@ember-data/adapter/rest'; +// @ts-expect-error import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private'; export default class ApplicationAdapter extends RESTAdapter { diff --git a/tests/embroider-basic-compat/app/models/user.ts b/tests/embroider-basic-compat/app/models/user.ts index 33d0be8ad43..f253c222fff 100644 --- a/tests/embroider-basic-compat/app/models/user.ts +++ b/tests/embroider-basic-compat/app/models/user.ts @@ -1,3 +1,4 @@ +// @ts-expect-error import Model, { attr } from '@ember-data/model'; export default class User extends Model { diff --git a/tests/embroider-basic-compat/config/environment.js b/tests/embroider-basic-compat/config/environment.js index 32410cf0b79..546974efdb3 100644 --- a/tests/embroider-basic-compat/config/environment.js +++ b/tests/embroider-basic-compat/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'embroider-basic-compat', environment, rootURL: '/', diff --git a/tests/embroider-basic-compat/ember-cli-build.js b/tests/embroider-basic-compat/ember-cli-build.js index 72dc141789f..01b71dcd385 100644 --- a/tests/embroider-basic-compat/ember-cli-build.js +++ b/tests/embroider-basic-compat/ember-cli-build.js @@ -5,7 +5,7 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { // Add options here 'ember-cli-babel': { enableTypeScriptTransform: true, diff --git a/tests/embroider-basic-compat/package.json b/tests/embroider-basic-compat/package.json index d461eff7c56..a1b53c809c6 100644 --- a/tests/embroider-basic-compat/package.json +++ b/tests/embroider-basic-compat/package.json @@ -16,8 +16,8 @@ }, "scripts": { "build": "ember build", - "lint:hbs": "ember-template-lint .", - "lint:old": "eslint --config ../../.eslintrc.js --ignore-path ../../.eslintignore .", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", + "check:types": "tsc --noEmit", "start": "ember serve", "test:embroider": "ember test --test-port=0", "_syncPnpm": "bun run sync-dependencies-meta-injected" @@ -55,6 +55,7 @@ "@embroider/webpack": "^3.2.1", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", "ember-cli-dependency-checker": "^3.3.2", @@ -71,7 +72,7 @@ "loader.js": "^4.7.0", "qunit": "^2.20.0", "qunit-dom": "^3.0.0", - "typescript": "~5.2.2" + "typescript": "^5.2.2" }, "engines": { "node": ">= 20.9.0" diff --git a/tests/embroider-basic-compat/testem.js b/tests/embroider-basic-compat/testem.js index fb97c3f065e..2d19b92e408 100644 --- a/tests/embroider-basic-compat/testem.js +++ b/tests/embroider-basic-compat/testem.js @@ -1,4 +1,4 @@ -// eslint-disable-next-line n/no-unpublished-require + const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console diff --git a/tests/embroider-basic-compat/tsconfig.json b/tests/embroider-basic-compat/tsconfig.json new file mode 100644 index 00000000000..3a781c7337e --- /dev/null +++ b/tests/embroider-basic-compat/tsconfig.json @@ -0,0 +1,30 @@ +{ + "include": ["app/**/*", "config/**/*", "tests/**/*"], + "baseUrl": ".", + "compilerOptions": { + "lib": ["DOM", "ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "strict": true, + "downlevelIteration": true, + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + + "noImplicitOverride": true, + + "experimentalDecorators": true, + + "incremental": true, + + "noEmit": true, + "declaration": false, + + "types": ["ember-source/types"], + "paths": {} + }, + "references": [] +} From aa973082b3442c4105180f5ff01b359bd8860764 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 12:45:26 -0800 Subject: [PATCH 10/17] Add tsconfig and eslintrc for tests/fastboot --- pnpm-lock.yaml | 5 ++- tests/fastboot/.eslintrc.cjs | 45 +++++++++++++++++++ tests/fastboot/app/adapters/application.ts | 2 + tests/fastboot/app/serializers/application.ts | 2 + tests/fastboot/config/environment.js | 2 +- tests/fastboot/ember-cli-build.js | 2 +- tests/fastboot/package.json | 7 +-- tests/fastboot/testem.js | 2 +- tests/fastboot/tsconfig.json | 30 +++++++++++++ 9 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 tests/fastboot/.eslintrc.cjs create mode 100644 tests/fastboot/tsconfig.json diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 42a144f24b4..a82699b1332 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3534,6 +3534,9 @@ importers: '@glimmer/tracking': specifier: ^1.1.2 version: 1.1.2 + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-cli: specifier: ~5.4.0 version: 5.4.0 @@ -3586,7 +3589,7 @@ importers: specifier: ^3.0.0 version: 3.0.0 typescript: - specifier: ~5.2.2 + specifier: ^5.2.2 version: 5.2.2 dependenciesMeta: '@ember-data/unpublished-test-infra': diff --git a/tests/fastboot/.eslintrc.cjs b/tests/fastboot/.eslintrc.cjs new file mode 100644 index 00000000000..8d6aa00ee89 --- /dev/null +++ b/tests/fastboot/.eslintrc.cjs @@ -0,0 +1,45 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const qunit = require('@warp-drive/internal-config/eslint/qunit.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application', '@ember/routing/route', '@ember/service'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults({ + files: ['./config/fastboot.js', './config/fastboot-testing.js'], + }), + typescript.defaults({ + rules: { + // TODO: Enable these once we get types working properly + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + }, + }), + qunit.defaults({ + files: ['tests/**/*.{js,ts}'], + allowedImports: ['@ember/object'], + }), + ], +}; diff --git a/tests/fastboot/app/adapters/application.ts b/tests/fastboot/app/adapters/application.ts index 091f5ab1225..f88acbac13d 100644 --- a/tests/fastboot/app/adapters/application.ts +++ b/tests/fastboot/app/adapters/application.ts @@ -1,4 +1,6 @@ +// @ts-expect-error import RESTAdapter from '@ember-data/adapter/rest'; +// @ts-expect-error import type { SnapshotRecordArray } from '@ember-data/legacy-compat/-private'; export default class ApplicationAdapter extends RESTAdapter { diff --git a/tests/fastboot/app/serializers/application.ts b/tests/fastboot/app/serializers/application.ts index 2129eaeaeef..0bcb026f0e5 100644 --- a/tests/fastboot/app/serializers/application.ts +++ b/tests/fastboot/app/serializers/application.ts @@ -1,4 +1,6 @@ +// @ts-expect-error import JSONSerializer from '@ember-data/serializer/json'; +// @ts-expect-error import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest'; export default JSONSerializer.extend(EmbeddedRecordsMixin, {}); diff --git a/tests/fastboot/config/environment.js b/tests/fastboot/config/environment.js index b2bf63e45f4..4ad322afa77 100644 --- a/tests/fastboot/config/environment.js +++ b/tests/fastboot/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'fastboot-test-app', environment, rootURL: '/', diff --git a/tests/fastboot/ember-cli-build.js b/tests/fastboot/ember-cli-build.js index dd83666aa50..85b2c4fea09 100644 --- a/tests/fastboot/ember-cli-build.js +++ b/tests/fastboot/ember-cli-build.js @@ -5,7 +5,7 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { // Add options here 'ember-cli-babel': { enableTypeScriptTransform: true, diff --git a/tests/fastboot/package.json b/tests/fastboot/package.json index c34d24d8a91..e25cf4d6ca6 100644 --- a/tests/fastboot/package.json +++ b/tests/fastboot/package.json @@ -16,8 +16,8 @@ }, "scripts": { "build": "ember build", - "lint:hbs": "ember-template-lint .", - "lint:old": "eslint --config ../../.eslintrc.js --ignore-path ../../.eslintignore .", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", + "check:types": "tsc --noEmit", "start": "ember serve", "test:fastboot": "ember test --test-port=0", "_syncPnpm": "bun run sync-dependencies-meta-injected" @@ -52,6 +52,7 @@ "@ember/test-helpers": "^3.2.0", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", "ember-cli-dependency-checker": "^3.3.2", @@ -69,7 +70,7 @@ "loader.js": "^4.7.0", "qunit": "^2.20.0", "qunit-dom": "^3.0.0", - "typescript": "~5.2.2" + "typescript": "^5.2.2" }, "engines": { "node": ">= 20.9.0" diff --git a/tests/fastboot/testem.js b/tests/fastboot/testem.js index fb97c3f065e..2d19b92e408 100644 --- a/tests/fastboot/testem.js +++ b/tests/fastboot/testem.js @@ -1,4 +1,4 @@ -// eslint-disable-next-line n/no-unpublished-require + const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console diff --git a/tests/fastboot/tsconfig.json b/tests/fastboot/tsconfig.json new file mode 100644 index 00000000000..04721744029 --- /dev/null +++ b/tests/fastboot/tsconfig.json @@ -0,0 +1,30 @@ +{ + "include": ["app/**/*", "config/**/*", "tests/**/*", "types/**/*"], + "baseUrl": ".", + "compilerOptions": { + "lib": ["DOM", "ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "strict": true, + "downlevelIteration": true, + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + + "noImplicitOverride": true, + + "experimentalDecorators": true, + + "incremental": true, + + "noEmit": true, + "declaration": false, + + "types": ["ember-source/types"], + "paths": {} + }, + "references": [] +} From 1621967c2375fbcc4acbe68a28cb3b57590d91dd Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 15:08:15 -0800 Subject: [PATCH 11/17] Add eslintrc for tests/main --- .vscode/settings.json | 3 +- config/eslint/diagnostic.cjs | 3 +- config/eslint/node.cjs | 9 +- config/eslint/qunit.cjs | 3 + pnpm-lock.yaml | 3 + .../integration/error-propagation-test.ts | 1 - tests/main/.eslintrc.cjs | 58 +++ tests/main/config/ember-try.js | 2 +- tests/main/ember-cli-build.js | 6 +- tests/main/holodeck.mjs | 3 +- tests/main/package.json | 2 + tests/main/testem.js | 2 +- .../relationships/belongs-to-test.js | 54 +-- .../acceptance/relationships/has-many-test.js | 84 ++-- .../acceptance/tracking-create-record-test.js | 10 +- .../acceptance/tracking-model-id-test.js | 10 +- tests/main/tests/helpers/accessors.ts | 7 +- .../tests/helpers/create-tracking-context.js | 4 +- tests/main/tests/helpers/watch-property.js | 14 +- .../adapter/build-url-mixin-test.js | 34 +- .../adapter/client-side-delete-test.js | 8 +- .../integration/adapter/find-all-test.js | 34 +- .../tests/integration/adapter/find-test.js | 12 +- .../adapter/handle-response-test.js | 6 +- .../adapter/json-api-adapter-test.js | 76 ++-- .../tests/integration/adapter/queries-test.js | 20 +- .../adapter/record-persistence-test.js | 40 +- .../integration/adapter/rest-adapter-test.js | 235 +++++------ .../rest-adapter/create-record-test.js | 2 +- .../adapter/rest-adapter/find-record-test.js | 10 +- .../integration/adapter/serialize-test.js | 8 +- .../integration/adapter/store-adapter-test.js | 296 +++++++------ .../tests/integration/application-test.js | 28 +- .../non-dasherized-lookups-test.js | 8 +- .../cache-handler/store-package-setup-test.ts | 20 +- .../integration/client-id-generation-test.js | 14 +- .../integration/identifiers/cache-test.ts | 12 +- .../identifiers/configuration-test.ts | 14 +- .../identifiers/new-records-test.ts | 2 +- .../identifiers/polymorphic-scenarios-test.ts | 57 +-- .../identifiers/record-identifier-for-test.ts | 26 +- .../integration/identifiers/scenarios-test.ts | 59 +-- .../tests/integration/model-errors-test.ts | 10 +- tests/main/tests/integration/peek-all-test.js | 4 +- .../polymorphic-belongs-to-test.js | 14 +- .../integration/record-array-manager-test.js | 16 +- .../tests/integration/record-array-test.js | 36 +- .../adapter-populated-record-array-test.js | 55 ++- .../record-arrays/peeked-records-test.js | 44 +- .../record-data/record-data-errors-test.ts | 43 +- .../record-data/record-data-state-test.ts | 45 +- .../record-data/record-data-test.ts | 69 +-- .../record-data/store-wrapper-test.ts | 33 +- .../records/collection-save-test.js | 24 +- .../records/concurrent-save-test.ts | 2 +- .../integration/records/create-record-test.js | 14 +- .../integration/records/delete-record-test.js | 78 ++-- .../integration/records/edit-record-test.js | 50 +-- .../tests/integration/records/error-test.js | 22 +- .../tests/integration/records/load-test.js | 16 +- .../records/new-record-unload-test.js | 28 +- .../records/property-changes-test.js | 10 +- .../records/relationship-changes-test.js | 2 +- .../tests/integration/records/reload-test.js | 83 ++-- .../integration/records/rematerialize-test.js | 14 +- .../tests/integration/records/save-test.js | 66 +-- .../tests/integration/records/unload-test.js | 126 +++--- .../integration/references/belongs-to-test.js | 126 +++--- .../integration/references/has-many-test.js | 82 ++-- .../integration/references/record-test.js | 74 ++-- .../relationships/belongs-to-test.js | 224 +++++----- .../relationships/has-many-test.js | 399 +++++++++--------- .../inverse-relationship-load-test.js | 164 +++---- .../relationships/json-api-links-test.js | 194 ++++----- .../relationships/many-to-many-test.js | 74 ++-- .../relationships/nested-relationship-test.js | 12 +- .../relationships/one-to-many-test.js | 122 +++--- .../relationships/one-to-one-test.js | 56 +-- .../relationships/relationship-links-test.js | 2 +- .../relationships/rollback-test.ts | 6 +- .../relationships/unload-new-record-test.js | 4 +- .../integration/request-state-service-test.ts | 52 +-- .../embedded-records-mixin-test.js | 142 +++---- .../serializers/json-api-serializer-test.js | 100 ++--- .../serializers/json-serializer-test.js | 246 +++++------ .../serializers/rest-serializer-test.js | 226 +++++----- tests/main/tests/integration/snapshot-test.js | 228 +++++----- .../tests/integration/store-extension-test.ts | 7 +- tests/main/tests/integration/store-test.js | 171 ++++---- .../integration/store/adapter-for-test.js | 34 +- .../store/json-api-validation-test.js | 8 +- .../integration/store/package-import-test.js | 4 +- .../integration/store/query-record-test.js | 12 +- .../integration/store/serializer-for-test.js | 34 +- .../store/store-creation-recursion-test.js | 4 +- tests/main/tests/test-helper.js | 2 +- tests/main/tests/unit/adapter-errors-test.js | 26 +- .../build-url-mixin/build-url-test.js | 40 +- .../build-url-mixin/path-for-type-test.js | 8 +- .../json-api-adapter/ajax-options-test.js | 70 +-- .../rest-adapter/ajax-options-test.js | 128 +++--- .../rest-adapter/detailed-message-test.js | 8 +- .../rest-adapter/fetch-options-test.js | 8 +- .../group-records-for-find-many-test.js | 18 +- .../custom-class-model-test.ts | 36 +- tests/main/tests/unit/many-array-test.js | 2 +- tests/main/tests/unit/model-test.js | 120 +++--- tests/main/tests/unit/model/attr-test.js | 30 +- .../tests/unit/model/init-properties-test.js | 30 +- tests/main/tests/unit/model/merge-test.js | 20 +- .../tests/unit/model/relationships-test.js | 19 +- .../model/relationships/belongs-to-test.js | 64 +-- .../unit/model/relationships/has-many-test.js | 182 ++++---- .../model/relationships/record-array-test.js | 6 +- .../unit/model/rollback-attributes-test.js | 63 ++- tests/main/tests/unit/promise-proxies-test.js | 27 +- .../adapter-populated-record-array-test.js | 30 +- .../unit/record-arrays/record-array-test.js | 50 +-- .../tests/unit/store/adapter-interop-test.js | 128 +++--- tests/main/tests/unit/store/asserts-test.js | 2 +- .../tests/unit/store/create-record-test.js | 22 +- tests/main/tests/unit/store/finders-test.js | 42 +- tests/main/tests/unit/store/model-for-test.js | 10 +- .../main/tests/unit/store/peek-record-test.js | 18 +- tests/main/tests/unit/store/push-test.js | 59 ++- tests/main/tests/unit/store/unload-test.js | 14 +- .../polymorphic-relationship-payloads-test.js | 42 +- .../unit/system/snapshot-record-array-test.js | 14 +- .../unit/utils/determine-body-promise-test.js | 6 +- .../unit/utils/parse-response-headers-test.js | 26 +- 130 files changed, 3215 insertions(+), 3165 deletions(-) create mode 100644 tests/main/.eslintrc.cjs diff --git a/.vscode/settings.json b/.vscode/settings.json index 3d96a190806..29de30d61be 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "turbo.json": "jsonc" }, "eslint.workingDirectories": [{ "mode": "auto" }, "packages/*", "tests/*"], - "editor.formatOnSave": true + "editor.formatOnSave": true, + "cSpell.words": ["Moomin"] } diff --git a/config/eslint/diagnostic.cjs b/config/eslint/diagnostic.cjs index 5f4b967ca59..64e44246891 100644 --- a/config/eslint/diagnostic.cjs +++ b/config/eslint/diagnostic.cjs @@ -12,11 +12,12 @@ function defaults(config = {}) { }), config?.rules, { - 'qunit/require-expect': 'off', 'qunit/no-assert-equal': 'off', 'qunit/no-assert-logical-expression': 'off', 'qunit/no-conditional-assertions': 'off', + 'qunit/no-early-return': 'off', 'qunit/no-ok-equality': 'off', + 'qunit/require-expect': 'off', } ), }; diff --git a/config/eslint/node.cjs b/config/eslint/node.cjs index daf752d7fc7..b90c70b2e81 100644 --- a/config/eslint/node.cjs +++ b/config/eslint/node.cjs @@ -27,7 +27,14 @@ function defaults(config) { function config(config) { const result = { - files: ['./.eslintrc.cjs', './babel.config.js', './ember-cli-build.js', './rollup.config.mjs', './testem.js'], + files: [ + './.eslintrc.cjs', + './babel.config.js', + './ember-cli-build.js', + './rollup.config.mjs', + './testem.js', + './config/ember-try.js', + ], parserOptions: { sourceType: config?.useModules ? 'module' : 'script', ecmaVersion: 2022, diff --git a/config/eslint/qunit.cjs b/config/eslint/qunit.cjs index 0f9207f6843..49cddfa736f 100644 --- a/config/eslint/qunit.cjs +++ b/config/eslint/qunit.cjs @@ -9,6 +9,7 @@ function defaults(config = {}) { allowedImports: [ '@ember/debug', '@ember/test-helpers', + '@ember/test-waiters', 'ember-qunit', 'qunit', ...(config.allowedImports ?? []), @@ -18,7 +19,9 @@ function defaults(config = {}) { { 'qunit/no-assert-logical-expression': 'off', 'qunit/no-conditional-assertions': 'off', + 'qunit/no-early-return': 'off', 'qunit/no-ok-equality': 'off', + 'qunit/require-expect': 'off', } ), }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a82699b1332..4434c31ab4c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3762,6 +3762,9 @@ importers: '@warp-drive/holodeck': specifier: workspace:5.5.0-alpha.11 version: file:packages/holodeck(@ember-data/request@5.5.0-alpha.11)(@warp-drive/core-types@5.5.0-alpha.11) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config broccoli-concat: specifier: ^4.2.5 version: 4.2.5 diff --git a/tests/ember-data__request/tests/integration/error-propagation-test.ts b/tests/ember-data__request/tests/integration/error-propagation-test.ts index d81421b2801..78b514f1ac5 100644 --- a/tests/ember-data__request/tests/integration/error-propagation-test.ts +++ b/tests/ember-data__request/tests/integration/error-propagation-test.ts @@ -17,7 +17,6 @@ module('RequestManager | Error Propagation', function () { assert.ok(true, 'catching handler triggered'); try { // await to catch, else error is curried - // eslint-disable-next-line qunit/no-early-return return await next(context.request); } catch (e) { assert.equal((e as Error).message, 'Oops!', 'We caught the error'); diff --git a/tests/main/.eslintrc.cjs b/tests/main/.eslintrc.cjs new file mode 100644 index 00000000000..d684313d796 --- /dev/null +++ b/tests/main/.eslintrc.cjs @@ -0,0 +1,58 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const qunit = require('@warp-drive/internal-config/eslint/qunit.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application', '@ember/routing/route', '@ember/service'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults(), + typescript.defaults({ + rules: { + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + }, + }), + qunit.defaults({ + files: ['tests/**/*.{js,ts}'], + allowedImports: [ + '@ember/application', + '@ember/array', + '@ember/array/proxy', + '@ember/component', + '@ember/component/helper', + '@ember/controller', + '@ember/object', + '@ember/object/computed', + '@ember/object/mixin', + '@ember/owner', + '@ember/service', + '@ember/string', + '@glimmer/component', + 'ember-inflector', + ], + }), + ], +}; diff --git a/tests/main/config/ember-try.js b/tests/main/config/ember-try.js index 1d86de32bac..dec1e9fcf68 100644 --- a/tests/main/config/ember-try.js +++ b/tests/main/config/ember-try.js @@ -1,4 +1,4 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const getChannelURL = require('ember-source-channel-url'); diff --git a/tests/main/ember-cli-build.js b/tests/main/ember-cli-build.js index f0732b64a2c..610d5ed2e7e 100644 --- a/tests/main/ember-cli-build.js +++ b/tests/main/ember-cli-build.js @@ -1,4 +1,4 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); @@ -38,7 +38,7 @@ module.exports = function (defaults) { terserSettings.enabled = false; } - let config = { + const config = { compatWith, includeDataAdapterInProduction: true, includeDataAdapter: true, @@ -57,7 +57,7 @@ module.exports = function (defaults) { features: require('@ember-data/private-build-infra/src/features')(isProd), env: require('@ember-data/private-build-infra/src/utilities/get-env')(), }; - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { emberData: Object.assign({}, config), babel: { // this ensures that the same build-time code stripping that is done diff --git a/tests/main/holodeck.mjs b/tests/main/holodeck.mjs index 1a7c32da003..2454015718e 100644 --- a/tests/main/holodeck.mjs +++ b/tests/main/holodeck.mjs @@ -1,7 +1,8 @@ -import { createServer } from '@warp-drive/holodeck'; import { dirname } from 'node:path'; import { fileURLToPath } from 'url'; +import { createServer } from '@warp-drive/holodeck'; + const __dirname = dirname(fileURLToPath(import.meta.url)); export default createServer({ diff --git a/tests/main/package.json b/tests/main/package.json index c416130aa1f..7f854ed68d8 100644 --- a/tests/main/package.json +++ b/tests/main/package.json @@ -15,6 +15,7 @@ "scripts": { "build:tests": "IS_TESTING=true EMBER_CLI_TEST_COMMAND=true ember build --output-path=dist-test --suppress-sizes", "build:production": "pnpm build:tests -e production", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "check:types": "tsc --noEmit", "examine": "export EXAM_PARALLEL_COUNT=$(./bin/calculate-test-jobs); ember exam --test-port=0 --path=dist-test --parallel=$EXAM_PARALLEL_COUNT --load-balance", "test:try-one": "ember try:one", @@ -112,6 +113,7 @@ "@types/qunit": "^2.19.8", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", "@warp-drive/holodeck": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "broccoli-concat": "^4.2.5", "broccoli-merge-trees": "^4.2.0", "broccoli-stew": "^3.0.0", diff --git a/tests/main/testem.js b/tests/main/testem.js index 101394b3ac5..41a3edfa5b9 100644 --- a/tests/main/testem.js +++ b/tests/main/testem.js @@ -1,4 +1,4 @@ -/* eslint-disable n/no-unpublished-require */ + const TestemConfig = require('@ember-data/unpublished-test-infra/src/testem/testem'); module.exports = TestemConfig; diff --git a/tests/main/tests/acceptance/relationships/belongs-to-test.js b/tests/main/tests/acceptance/relationships/belongs-to-test.js index 6dba0b96ffc..8568a201508 100644 --- a/tests/main/tests/acceptance/relationships/belongs-to-test.js +++ b/tests/main/tests/acceptance/relationships/belongs-to-test.js @@ -65,7 +65,7 @@ class TestAdapter extends JSONAPIAdapter { return this.pausePromise.then(() => this._nextPayload()); } - let payload = this._payloads.shift(); + const payload = this._payloads.shift(); if (payload === undefined) { this.assert.ok(false, 'Too many adapter requests have been made!'); @@ -103,7 +103,7 @@ class TestAdapter extends JSONAPIAdapter { } function makePeopleWithRelationshipData() { - let people = [ + const people = [ { type: 'person', id: '1:no-children-or-parent', @@ -198,7 +198,7 @@ function makePeopleWithRelationshipData() { }, ]; - let peopleHash = {}; + const peopleHash = {}; people.forEach((person) => { peopleHash[person.id] = person; }); @@ -215,7 +215,7 @@ module('async belongs-to rendering tests', function (hooks) { setupRenderingTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('model:pet', Pet); owner.register('adapter:application', TestAdapter); @@ -233,7 +233,7 @@ module('async belongs-to rendering tests', function (hooks) { module('for local changes', function (hooks) { hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('model:pet', Pet); }); @@ -324,7 +324,7 @@ module('async belongs-to rendering tests', function (hooks) { }); test('async belongsTo returns correct new value after a local change', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { type: 'person', id: '1', @@ -359,8 +359,8 @@ module('async belongs-to rendering tests', function (hooks) { ], }); - let shen = store.peekRecord('pet', '1'); - let pirate = store.peekRecord('pet', '2'); + const shen = store.peekRecord('pet', '1'); + const pirate = store.peekRecord('pet', '2'); let bestDog = await chris.bestDog; this.set('chris', chris); @@ -410,8 +410,8 @@ module('async belongs-to rendering tests', function (hooks) { module('for data-no-link scenarios', function () { test('We can render an async belongs-to', async function (assert) { - let people = makePeopleWithRelationshipData(); - let sedona = store.push({ + const people = makePeopleWithRelationshipData(); + const sedona = store.push({ data: people.dict['5:has-parent-no-children'], }); @@ -428,8 +428,8 @@ module('async belongs-to rendering tests', function (hooks) { }); test('We can delete an async belongs-to', async function (assert) { - let people = makePeopleWithRelationshipData(); - let sedona = store.push({ + const people = makePeopleWithRelationshipData(); + const sedona = store.push({ data: people.dict['5:has-parent-no-children'], }); @@ -442,9 +442,9 @@ module('async belongs-to rendering tests', function (hooks) {

{{this.sedona.parent.name}}

`); - let parent = await sedona.parent; + const parent = await sedona.parent; await parent.destroyRecord(); - let newParent = await sedona.parent; + const newParent = await sedona.parent; assert.strictEqual(newParent, null, 'We no longer have a parent'); assert.strictEqual( @@ -455,8 +455,8 @@ module('async belongs-to rendering tests', function (hooks) { }); test('Re-rendering an async belongsTo does not cause a new fetch', async function (assert) { - let people = makePeopleWithRelationshipData(); - let sedona = store.push({ + const people = makePeopleWithRelationshipData(); + const sedona = store.push({ data: people.dict['5:has-parent-no-children'], }); @@ -479,8 +479,8 @@ module('async belongs-to rendering tests', function (hooks) { }); test('Rendering an async belongs-to whose fetch fails does not trigger a new request', async function (assert) { - let people = makePeopleWithRelationshipData(); - let sedona = store.push({ + const people = makePeopleWithRelationshipData(); + const sedona = store.push({ data: people.dict['5:has-parent-no-children'], }); @@ -512,7 +512,7 @@ module('async belongs-to rendering tests', function (hooks) { // Here we assign our handler to the corresponding global, window property window.addEventListener('unhandledrejection', globalPromiseRejectionHandler, true); - let originalPushResult = assert.pushResult; + const originalPushResult = assert.pushResult; assert.pushResult = function (result) { if ( result.result === false && @@ -531,8 +531,8 @@ module('async belongs-to rendering tests', function (hooks) { const relationship = sedona.belongsTo('parent').belongsToRelationship; const { state, definition } = relationship; - let RelationshipPromiseCache = LEGACY_SUPPORT.get(sedona)._relationshipPromisesCache; - let RelationshipProxyCache = LEGACY_SUPPORT.get(sedona)._relationshipProxyCache; + const RelationshipPromiseCache = LEGACY_SUPPORT.get(sedona)._relationshipPromisesCache; + const RelationshipProxyCache = LEGACY_SUPPORT.get(sedona)._relationshipProxyCache; assert.true(definition.isAsync, 'The relationship is async'); assert.false(state.isEmpty, 'The relationship is not empty'); @@ -545,7 +545,7 @@ module('async belongs-to rendering tests', function (hooks) { assert.false(!!relationship.link, 'The relationship does not have a link'); try { - let result = sedona.parent.content; + const result = sedona.parent.content; assert.strictEqual(result, null, 're-access is safe'); } catch (e) { assert.ok(false, `Re-accessing unexpectedly resulted in rejected promise error: ${e.message}`); @@ -564,8 +564,8 @@ module('async belongs-to rendering tests', function (hooks) { test('accessing a linked async belongs-to whose fetch fails does not error for null proxy content', async function (assert) { assert.expect(3); - let people = makePeopleWithRelationshipData(); - let sedona = store.push({ + const people = makePeopleWithRelationshipData(); + const sedona = store.push({ data: people.dict['6:has-linked-parent'], }); @@ -596,8 +596,8 @@ module('async belongs-to rendering tests', function (hooks) { test('Can reset a previously failed linked async belongs-to', async function (assert) { assert.expect(5); - let people = makePeopleWithRelationshipData(); - let sedona = store.push({ + const people = makePeopleWithRelationshipData(); + const sedona = store.push({ data: people.dict['6:has-linked-parent'], }); @@ -615,7 +615,7 @@ module('async belongs-to rendering tests', function (hooks) { // Here we assign our handler to the corresponding global, window property window.addEventListener('unhandledrejection', globalPromiseRejectionHandler, true); - let originalPushResult = assert.pushResult; + const originalPushResult = assert.pushResult; assert.pushResult = function (result) { if (result.result === false && result.message === 'global failure: Error: person not found') { return; diff --git a/tests/main/tests/acceptance/relationships/has-many-test.js b/tests/main/tests/acceptance/relationships/has-many-test.js index e83dc83d1a8..df8e3e4dc4c 100644 --- a/tests/main/tests/acceptance/relationships/has-many-test.js +++ b/tests/main/tests/acceptance/relationships/has-many-test.js @@ -54,7 +54,7 @@ class TestAdapter extends JSONAPIAdapter { if (this.isPaused) { return this.pausePromise.then(() => this._nextPayload()); } - let payload = this._payloads.shift(); + const payload = this._payloads.shift(); if (payload === undefined) { this.assert.ok(false, 'Too many adapter requests have been made!'); @@ -84,7 +84,7 @@ class TestAdapter extends JSONAPIAdapter { } function makePeopleWithRelationshipData() { - let people = [ + const people = [ { type: 'person', id: '1:no-children-or-parent', @@ -166,7 +166,7 @@ function makePeopleWithRelationshipData() { }, ]; - let peopleHash = {}; + const peopleHash = {}; people.forEach((person) => { peopleHash[person.id] = person; }); @@ -178,12 +178,12 @@ function makePeopleWithRelationshipData() { } function makePeopleWithRelationshipLinks(removeData = true) { - let people = makePeopleWithRelationshipData(); - let linkPayloads = (people.links = {}); + const people = makePeopleWithRelationshipData(); + const linkPayloads = (people.links = {}); people.all.map((person) => { Object.keys(person.relationships).forEach((relName) => { - let rel = person.relationships[relName]; + const rel = person.relationships[relName]; let data = rel.data; if (removeData === true) { @@ -224,8 +224,8 @@ module('async has-many rendering tests', function (hooks) { test('We can render an async hasMany', async function (assert) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); - let people = makePeopleWithRelationshipData(); - let parent = store.push({ + const people = makePeopleWithRelationshipData(); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], }); @@ -245,7 +245,7 @@ module('async has-many rendering tests', function (hooks) { `); - let names = findAll('li').map((e) => e.textContent); + const names = findAll('li').map((e) => e.textContent); assert.deepEqual(names, ['Selena has a parent', 'Sedona has a parent'], 'We rendered the names'); }); @@ -253,8 +253,8 @@ module('async has-many rendering tests', function (hooks) { test('Re-rendering an async hasMany does not cause a new fetch', async function (assert) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); - let people = makePeopleWithRelationshipData(); - let parent = store.push({ + const people = makePeopleWithRelationshipData(); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], }); @@ -414,8 +414,8 @@ module('async has-many rendering tests', function (hooks) { test('We can render an async hasMany with a link', async function (assert) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); - let people = makePeopleWithRelationshipLinks(true); - let parent = store.push({ + const people = makePeopleWithRelationshipLinks(true); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], }); @@ -432,7 +432,7 @@ module('async has-many rendering tests', function (hooks) { `); - let names = findAll('li').map((e) => e.textContent); + const names = findAll('li').map((e) => e.textContent); assert.deepEqual(names, ['Selena has a parent', 'Sedona has a parent'], 'We rendered the names'); }); @@ -440,8 +440,8 @@ module('async has-many rendering tests', function (hooks) { test('Re-rendering an async hasMany with a link does not cause a new fetch', async function (assert) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); - let people = makePeopleWithRelationshipLinks(true); - let parent = store.push({ + const people = makePeopleWithRelationshipLinks(true); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], }); @@ -479,8 +479,8 @@ module('async has-many rendering tests', function (hooks) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); assert.expect(11); - let people = makePeopleWithRelationshipLinks(true); - let parent = store.push({ + const people = makePeopleWithRelationshipLinks(true); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], }); @@ -514,7 +514,7 @@ module('async has-many rendering tests', function (hooks) { // Here we assign our handler to the corresponding global, window property window.addEventListener('unhandledrejection', globalPromiseRejectionHandler, true); - let originalPushResult = assert.pushResult; + const originalPushResult = assert.pushResult; assert.pushResult = function (result) { if ( result.result === false && @@ -534,13 +534,13 @@ module('async has-many rendering tests', function (hooks) { `); - let names = findAll('li').map((e) => e.textContent); + const names = findAll('li').map((e) => e.textContent); assert.deepEqual(names, [], 'We rendered no names'); - let relationshipState = parent.hasMany('children').hasManyRelationship; - let RelationshipPromiseCache = LEGACY_SUPPORT.get(parent)._relationshipPromisesCache; - let RelationshipProxyCache = LEGACY_SUPPORT.get(parent)._relationshipProxyCache; + const relationshipState = parent.hasMany('children').hasManyRelationship; + const RelationshipPromiseCache = LEGACY_SUPPORT.get(parent)._relationshipPromisesCache; + const RelationshipProxyCache = LEGACY_SUPPORT.get(parent)._relationshipProxyCache; assert.true(relationshipState.definition.isAsync, 'The relationship is async'); assert.true( @@ -563,8 +563,8 @@ module('async has-many rendering tests', function (hooks) { test('We can render an async hasMany with a link and data', async function (assert) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); - let people = makePeopleWithRelationshipLinks(false); - let parent = store.push({ + const people = makePeopleWithRelationshipLinks(false); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], }); @@ -581,7 +581,7 @@ module('async has-many rendering tests', function (hooks) { `); - let names = findAll('li').map((e) => e.textContent); + const names = findAll('li').map((e) => e.textContent); assert.deepEqual(names, ['Selena has a parent', 'Sedona has a parent'], 'We rendered the names'); }); @@ -589,8 +589,8 @@ module('async has-many rendering tests', function (hooks) { test('Rendering an async hasMany with a link and data where data has been side-loaded does not fetch the link', async function (assert) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); - let people = makePeopleWithRelationshipLinks(false); - let parent = store.push({ + const people = makePeopleWithRelationshipLinks(false); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], included: [people.dict['4:has-parent-no-children'], people.dict['5:has-parent-no-children']], }); @@ -609,7 +609,7 @@ module('async has-many rendering tests', function (hooks) { `); - let names = findAll('li').map((e) => e.textContent); + const names = findAll('li').map((e) => e.textContent); assert.deepEqual(names, ['Selena has a parent', 'Sedona has a parent'], 'We rendered the names'); }); @@ -617,8 +617,8 @@ module('async has-many rendering tests', function (hooks) { test('Re-rendering an async hasMany with a link and data does not cause a new fetch', async function (assert) { const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); - let people = makePeopleWithRelationshipLinks(false); - let parent = store.push({ + const people = makePeopleWithRelationshipLinks(false); + const parent = store.push({ data: people.dict['3:has-2-children-and-parent'], }); @@ -803,7 +803,7 @@ module('autotracking has-many', function (hooks) { let store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('adapter:application', TestAdapter); owner.register('serializer:application', JSONAPISerializer); @@ -830,7 +830,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{this.sortedChildren.length}}

@@ -844,8 +844,8 @@ module('autotracking has-many', function (hooks) { this.owner.register('template:components/children-list', layout); store.createRecord('person', { id: '1', name: 'Doodad' }); - let person = store.peekRecord('person', '1'); - let children = await person.children; + const person = store.peekRecord('person', '1'); + const children = await person.children; this.model = { person, children }; await render(hbs``); @@ -877,7 +877,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{@person.children.length}}

@@ -925,7 +925,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{this.sortedChildren.length}}

@@ -975,7 +975,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{this.firstChild.name}}

@@ -1016,7 +1016,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{this.children.length}}

@@ -1066,7 +1066,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{this.children.length}}

@@ -1131,7 +1131,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{this.children.length}}

@@ -1216,7 +1216,7 @@ module('autotracking has-many', function (hooks) { } } - let layout = hbs` + const layout = hbs`

{{this.allPeople.length}}

diff --git a/tests/main/tests/acceptance/tracking-create-record-test.js b/tests/main/tests/acceptance/tracking-create-record-test.js index 75dfbddf58f..2d363a84208 100644 --- a/tests/main/tests/acceptance/tracking-create-record-test.js +++ b/tests/main/tests/acceptance/tracking-create-record-test.js @@ -32,7 +32,7 @@ module('acceptance/tracking-transactions', function (hooks) { const records = arr.filter((r) => r.isNew); if (records.length === 0) { // invalidate length - let record = this.store.createRecord('widget', { name: 'Chris' }); + const record = this.store.createRecord('widget', { name: 'Chris' }); records.push(record); } return records; @@ -40,7 +40,7 @@ module('acceptance/tracking-transactions', function (hooks) { } } - let layout = hbs` + const layout = hbs`
    {{#each this.widgets as |widget|}}
  • {{widget.name}} {{if widget.isValid 'Is Valid' 'Is Invalid'}}
  • @@ -84,7 +84,7 @@ module('acceptance/tracking-transactions', function (hooks) { const records = arr.filter((r) => r.isNew); if (records.length === 0) { // invalidate length - let record = this.store.createRecord('widget', { name }); + const record = this.store.createRecord('widget', { name }); records.push(record); } return records; @@ -96,7 +96,7 @@ module('acceptance/tracking-transactions', function (hooks) { } } - let layout = hbs` + const layout = hbs`
      {{#each this.widgets as |widget|}}
    • {{widget.name}} {{if widget.isValid 'Is Valid' 'Is Invalid'}}
    • @@ -175,7 +175,7 @@ module('acceptance/tracking-transactions', function (hooks) { } } - let layout = hbs` + const layout = hbs`
        {{#each this.widgets.data as |widget|}}
      • {{widget.name}} {{if widget.isValid 'Is Valid' 'Is Invalid'}}
      • diff --git a/tests/main/tests/acceptance/tracking-model-id-test.js b/tests/main/tests/acceptance/tracking-model-id-test.js index 19007aa0b40..7930ffd6c24 100644 --- a/tests/main/tests/acceptance/tracking-model-id-test.js +++ b/tests/main/tests/acceptance/tracking-model-id-test.js @@ -20,13 +20,13 @@ class Widget extends Model { class WidgetList extends Component { get sortedWidgets() { - let { widgets } = this.args; + const { widgets } = this.args; return widgets.slice().sort((a, b) => b.numericId - a.numericId); } } -let layout = hbs` +const layout = hbs`
          {{#each this.sortedWidgets as |widget index|}}
        • @@ -57,7 +57,7 @@ module('acceptance/tracking-model-id - tracking model id', function (hooks) { setupRenderingTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:widget', Widget); owner.register('component:widget-list', WidgetList); owner.register('template:components/widget-list', layout); @@ -66,7 +66,7 @@ module('acceptance/tracking-model-id - tracking model id', function (hooks) { }); test("can track model id's without using get", async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.createRecord('widget', { id: '1', name: 'Doodad' }); store.createRecord('widget', { id: '3', name: 'Gizmo' }); store.createRecord('widget', { id: '2', name: 'Gadget' }); @@ -82,7 +82,7 @@ module('acceptance/tracking-model-id - tracking model id', function (hooks) { assert.dom('ul>li.widget1>div.name').containsText('Gadget'); assert.dom('ul>li.widget2>div.name').containsText('Doodad'); - let contraption = store.createRecord('widget', { name: 'Contraption' }); + const contraption = store.createRecord('widget', { name: 'Contraption' }); await contraption.save(); await settled(); diff --git a/tests/main/tests/helpers/accessors.ts b/tests/main/tests/helpers/accessors.ts index 564d48095c1..b776d4dd7b3 100644 --- a/tests/main/tests/helpers/accessors.ts +++ b/tests/main/tests/helpers/accessors.ts @@ -1,11 +1,10 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; - import { graphFor } from '@ember-data/graph/-private'; import type { ImplicitEdge } from '@ember-data/graph/-private/edges/implicit'; import type { GraphEdge } from '@ember-data/graph/-private/graph'; import type Store from '@ember-data/store'; import { recordIdentifierFor } from '@ember-data/store'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; export function getRelationshipStateForRecord(record: { store: Store }, propertyName: string): GraphEdge { const identifier = recordIdentifierFor(record); @@ -31,9 +30,9 @@ export function implicitRelationshipsFor( if (!rels) { throw new Error(`Expected at least one relationship to be populated`); } - let implicits = Object.create(null); + const implicits = Object.create(null); Object.keys(rels).forEach((key) => { - let rel = rels[key]!; + const rel = rels[key]!; if (rel.definition.isImplicit) { implicits[key] = rel; } diff --git a/tests/main/tests/helpers/create-tracking-context.js b/tests/main/tests/helpers/create-tracking-context.js index 21b04279100..378f85a4664 100644 --- a/tests/main/tests/helpers/create-tracking-context.js +++ b/tests/main/tests/helpers/create-tracking-context.js @@ -7,7 +7,7 @@ import { hbs } from 'ember-cli-htmlbars'; export default async function createTrackingContext(owner, props) { let instance; - let testKeys = Object.keys(props); + const testKeys = Object.keys(props); class TestComponent extends Component { @tracked count = 1; @@ -22,7 +22,7 @@ export default async function createTrackingContext(owner, props) { } } - let defs = {}; + const defs = {}; testKeys.forEach((key) => (defs[key] = Object.getOwnPropertyDescriptor(props, key))); Object.defineProperties(TestComponent.prototype, defs); diff --git a/tests/main/tests/helpers/watch-property.js b/tests/main/tests/helpers/watch-property.js index 186f02688c4..35ced70ad1e 100644 --- a/tests/main/tests/helpers/watch-property.js +++ b/tests/main/tests/helpers/watch-property.js @@ -39,7 +39,7 @@ function makeCounter() { } export function watchProperty(obj, propertyName) { - let { counter, increment } = makeCounter(); + const { counter, increment } = makeCounter(); function observe() { increment(); @@ -72,21 +72,21 @@ export async function startWatching() { } export function watchProperties(obj, propertyNames) { - let watched = {}; - let counters = {}; + const watched = {}; + const counters = {}; if (!Array.isArray(propertyNames)) { throw new Error(`Must call watchProperties with an array of propertyNames to watch, received ${propertyNames}`); } for (let i = 0; i < propertyNames.length; i++) { - let propertyName = propertyNames[i]; + const propertyName = propertyNames[i]; if (watched[propertyName] !== undefined) { throw new Error(`Cannot watch the same property ${propertyName} more than once`); } - let { counter, increment } = makeCounter(); + const { counter, increment } = makeCounter(); watched[propertyName] = increment; counters[propertyName] = counter; } @@ -101,10 +101,10 @@ QUnit.assert.watchedPropertyCounts = function assertWatchedPropertyCount(watched throw new Error('Expected to receive the return value of watchProperties: an object containing counters'); } - let counters = watchedObject.counters; + const counters = watchedObject.counters; Object.keys(expectedCounts).forEach((propertyName) => { - let counter = counters[propertyName]; + const counter = counters[propertyName]; let expectedCount = expectedCounts[propertyName]; let assertionText = label; diff --git a/tests/main/tests/integration/adapter/build-url-mixin-test.js b/tests/main/tests/integration/adapter/build-url-mixin-test.js index 00038c8189a..6d45121a1f9 100644 --- a/tests/main/tests/integration/adapter/build-url-mixin-test.js +++ b/tests/main/tests/integration/adapter/build-url-mixin-test.js @@ -24,7 +24,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f } hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; class SuperUser extends Model {} owner.register('adapter:application', class extends RESTAdapter {}); @@ -81,7 +81,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ posts: [{ id: '1', links: { comments: 'comments' } }] }); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); ajaxResponse({ comments: [{ id: '1' }] }); await post.comments; @@ -108,7 +108,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ posts: [{ id: '1', links: { comments: '/api/v1/posts/1/comments' } }] }); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); ajaxResponse({ comments: [{ id: '1' }] }); await post.comments; @@ -135,7 +135,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ posts: [{ id: '1', links: { comments: '/api/v1/posts/1/comments' } }] }); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); ajaxResponse({ comments: [{ id: '1' }] }); await post.comments; @@ -162,7 +162,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ posts: [{ id: '1', links: { comments: '/api/v1/posts/1/comments' } }] }); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); ajaxResponse({ comments: [{ id: '1' }] }); await post.comments; @@ -196,7 +196,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ], }); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); ajaxResponse({ comments: [{ id: '1' }] }); await post.comments; @@ -206,7 +206,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f test('buildURL - with camelized names', async function (assert) { adapter.setProperties({ pathForType(type) { - let decamelized = decamelize(type); + const decamelized = decamelize(type); return underscore(pluralize(decamelized)); }, }); @@ -236,7 +236,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ comments: [{ id: '1' }] }); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '2', @@ -270,7 +270,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f adapter.coalesceFindRequests = true; ajaxResponse({ comments: [{ id: '1' }, { id: '2' }, { id: '3' }] }); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '2', @@ -309,13 +309,13 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ comments: [{ id: '1' }] }); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '2', }, }); - let comment = store.createRecord('comment'); + const comment = store.createRecord('comment'); comment.set('post', post); await comment.save(); assert.strictEqual(passedUrl, '/posts/2/comments/'); @@ -338,7 +338,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f return '/posts/' + snapshot.belongsTo('post', { id: true }) + '/comments/'; }; - let post = store.push({ + const post = store.push({ data: { id: '2', type: 'post', @@ -350,7 +350,7 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ comments: [{ id: '1' }] }); - let comment = store.createRecord('comment'); + const comment = store.createRecord('comment'); comment.set('post', post); await comment.save(); @@ -377,13 +377,13 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ comments: [{ id: '1' }] }); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '2', }, }); - let comment = store.push({ + const comment = store.push({ data: { type: 'comment', id: '1', @@ -414,13 +414,13 @@ module('integration/adapter/build-url-mixin - BuildURLMixin with RESTAdapter', f ajaxResponse({ comments: [{ id: '1' }] }); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '2', }, }); - let comment = store.push({ + const comment = store.push({ data: { type: 'comment', id: '1', diff --git a/tests/main/tests/integration/adapter/client-side-delete-test.js b/tests/main/tests/integration/adapter/client-side-delete-test.js index ceeb642300b..becb9ceee78 100644 --- a/tests/main/tests/integration/adapter/client-side-delete-test.js +++ b/tests/main/tests/integration/adapter/client-side-delete-test.js @@ -26,8 +26,8 @@ module('integration/adapter/store-adapter - client-side delete', function (hooks this.owner.register('model:bookstore', Bookstore); this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function (_store, _modelClass, snapshot) { if (snapshot.adapterOptions.clientSideDelete) { @@ -37,7 +37,7 @@ module('integration/adapter/store-adapter - client-side delete', function (hooks assert.ok(false, 'unreachable'); }; - let bookstore = store.push({ + const bookstore = store.push({ data: { id: '1', type: 'bookstore', @@ -74,7 +74,7 @@ module('integration/adapter/store-adapter - client-side delete', function (hooks 'initial hasmany loaded' ); - let book2 = store.peekRecord('book', '2'); + const book2 = store.peekRecord('book', '2'); await book2.destroyRecord({ adapterOptions: { clientSideDelete: true } }); diff --git a/tests/main/tests/integration/adapter/find-all-test.js b/tests/main/tests/integration/adapter/find-all-test.js index e7168942695..71d413c536c 100644 --- a/tests/main/tests/integration/adapter/find-all-test.js +++ b/tests/main/tests/integration/adapter/find-all-test.js @@ -28,7 +28,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function let store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('serializer:application', class extends JSONAPISerializer {}); @@ -38,7 +38,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function test("When all records for a type are requested, the store should call the adapter's `findAll` method.", async function (assert) { assert.expect(5); - let adapter = store.adapterFor('person'); + const adapter = store.adapterFor('person'); adapter.findAll = () => { // this will get called twice @@ -57,11 +57,11 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); }; - let allRecords = await store.findAll('person'); + const allRecords = await store.findAll('person'); assert.strictEqual(allRecords.length, 1, "the record array's length is 1 after a record is loaded into it"); assert.strictEqual(allRecords[0].name, 'Braaaahm Dale', 'the first item in the record array is Braaaahm Dale'); - let all = await store.findAll('person'); + const all = await store.findAll('person'); // Only one record array per type should ever be created (identity map) assert.strictEqual( allRecords, @@ -72,7 +72,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function test('When all records for a type are requested, a rejection should reject the promise', async function (assert) { assert.expect(5); - let adapter = store.adapterFor('person'); + const adapter = store.adapterFor('person'); let count = 0; adapter.findAll = () => { @@ -96,7 +96,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function } }; - let all = await store.findAll('person').catch(() => { + const all = await store.findAll('person').catch(() => { assert.ok(true, 'The rejection should get here'); return store.findAll('person'); }); @@ -121,7 +121,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function // Create a new, unsaved record in the store store.createRecord('person', { name: 'Alex MacCaw' }); - let allRecords = store.peekAll('person'); + const allRecords = store.peekAll('person'); assert.strictEqual(allRecords.length, 2, "the record array's length is 2"); assert.strictEqual(allRecords[0].name, 'Jeremy Ashkenas', 'the first item in the record array is Jeremy Ashkenas'); @@ -131,7 +131,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function test('When all records for a type are requested, records that are created on the client should be added to the record array.', async function (assert) { assert.expect(3); - let allRecords = store.peekAll('person'); + const allRecords = store.peekAll('person'); assert.strictEqual( allRecords.length, @@ -147,7 +147,7 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); testInDebug('When all records are requested, assert the payload is not blank', async function (assert) { - let adapter = store.adapterFor('person'); + const adapter = store.adapterFor('person'); adapter.findAll = () => Promise.resolve({}); assert.expectAssertion( @@ -157,8 +157,8 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); test('isUpdating is true while records are fetched', async function (assert) { - let findAllDeferred = createDeferred(); - let adapter = store.adapterFor('person'); + const findAllDeferred = createDeferred(); + const adapter = store.adapterFor('person'); adapter.findAll = () => findAllDeferred.promise; adapter.shouldReloadAll = () => true; @@ -171,10 +171,10 @@ module('integration/adapter/find-all - Finding All Records of a Type', function ], }); - let persons = store.peekAll('person'); + const persons = store.peekAll('person'); assert.strictEqual(persons.length, 1); - let promise = store.findAll('person'); + const promise = store.findAll('person'); assert.true(persons.isUpdating); @@ -186,8 +186,8 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); test('isUpdating is true while records are fetched in the background', async function (assert) { - let findAllDeferred = createDeferred(); - let adapter = store.adapterFor('person'); + const findAllDeferred = createDeferred(); + const adapter = store.adapterFor('person'); adapter.findAll = () => { return findAllDeferred.promise; }; @@ -223,8 +223,8 @@ module('integration/adapter/find-all - Finding All Records of a Type', function }); test('isUpdating is false if records are not fetched in the background', async function (assert) { - let findAllDeferred = createDeferred(); - let adapter = store.adapterFor('person'); + const findAllDeferred = createDeferred(); + const adapter = store.adapterFor('person'); adapter.findAll = () => { return findAllDeferred.promise; }; diff --git a/tests/main/tests/integration/adapter/find-test.js b/tests/main/tests/integration/adapter/find-test.js index f5431c76539..9a1cafc372c 100644 --- a/tests/main/tests/integration/adapter/find-test.js +++ b/tests/main/tests/integration/adapter/find-test.js @@ -47,8 +47,8 @@ module('integration/adapter - Finding Records', function (hooks) { const store = this.owner.lookup('service:store'); - let promise1 = store.findRecord('person', '1'); - let promise2 = store.findRecord('person', '1'); + const promise1 = store.findRecord('person', '1'); + const promise2 = store.findRecord('person', '1'); await promise1; await promise2; @@ -64,7 +64,7 @@ module('integration/adapter - Finding Records', function (hooks) { this.owner.register('serializer:application', class extends JSONAPISerializer {}); let resolveFindRecordPromise; - let findRecordPromise = new Promise((resolve) => (resolveFindRecordPromise = resolve)); + const findRecordPromise = new Promise((resolve) => (resolveFindRecordPromise = resolve)); this.owner.register( 'adapter:person', @@ -75,14 +75,14 @@ module('integration/adapter - Finding Records', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let firstPlayerRequest = store.findRecord('person', '1').then(function (firstPlayerRequest) { + const firstPlayerRequest = store.findRecord('person', '1').then(function (firstPlayerRequest) { assert.strictEqual(firstPlayerRequest.id, '1'); assert.strictEqual(firstPlayerRequest.name, 'Totono Grisales'); }); - let secondPlayerRequest = store.findRecord('person', '1').then(function (secondPlayerRequest) { + const secondPlayerRequest = store.findRecord('person', '1').then(function (secondPlayerRequest) { assert.strictEqual(secondPlayerRequest.id, '1'); assert.strictEqual(secondPlayerRequest.name, 'Totono Grisales'); }); diff --git a/tests/main/tests/integration/adapter/handle-response-test.js b/tests/main/tests/integration/adapter/handle-response-test.js index c08b60f2ae1..1627bef5bdb 100644 --- a/tests/main/tests/integration/adapter/handle-response-test.js +++ b/tests/main/tests/integration/adapter/handle-response-test.js @@ -31,7 +31,7 @@ module('integration/adapter/handle-response', function (hooks) { test('handleResponse is called with normal response', async function (assert) { let handleResponseCalled = 0; - let samplePayload = { + const samplePayload = { data: [ { id: '1', @@ -72,7 +72,7 @@ module('integration/adapter/handle-response', function (hooks) { test('handleResponse is called with empty array response', async function (assert) { let handleResponseCalled = 0; - let samplePayload = { + const samplePayload = { data: [], }; @@ -179,7 +179,7 @@ module('integration/adapter/handle-response', function (hooks) { test('handleResponse is called with correct parameters on string response with 422 status', async function (assert) { let handleResponseCalled = 0; - let errorObject = { errors: {} }; + const errorObject = { errors: {} }; this.server.get('/people', function () { return ['422', { 'Content-Type': 'application/json' }, JSON.stringify(errorObject)]; diff --git a/tests/main/tests/integration/adapter/json-api-adapter-test.js b/tests/main/tests/integration/adapter/json-api-adapter-test.js index 711e51811f3..a8790bec90d 100644 --- a/tests/main/tests/integration/adapter/json-api-adapter-test.js +++ b/tests/main/tests/integration/adapter/json-api-adapter-test.js @@ -114,7 +114,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1', 'Builds URL correctly'); assert.strictEqual(post.id, '1', 'Stores record with correct id'); @@ -185,7 +185,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let posts = await store.findAll('post'); + const posts = await store.findAll('post'); assert.strictEqual(passedUrl[0], '/posts'); @@ -233,7 +233,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let posts = await store.query('post', { filter: { id: '1' } }); + const posts = await store.query('post', { filter: { id: '1' } }); assert.strictEqual(passedUrl[0], '/posts', 'Builds correct URL'); assert.deepEqual(passedHash[0], { data: { filter: { id: '1' } } }, 'Sends correct params to adapter'); @@ -255,7 +255,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.queryRecord('post', {}); + const post = await store.queryRecord('post', {}); assert.strictEqual(passedUrl[0], '/posts', 'Builds correc URL'); assert.strictEqual(post.title, 'Ember.js rocks', 'Sets correct title to record'); @@ -268,7 +268,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.queryRecord('post', {}); + const post = await store.queryRecord('post', {}); assert.strictEqual(passedUrl[0], '/posts', 'Builds correct URL'); assert.strictEqual(post, null, 'Returns null when adapter response is null'); @@ -323,14 +323,14 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1', 'The primary record post:1 was fetched by the correct url'); assert.strictEqual(post.id, '1', 'Stores record using the correct id'); assert.strictEqual(post.title, 'Ember.js rocks', 'Sets correct title to record'); - let author = await post.author; + const author = await post.author; assert.strictEqual( passedUrl[1], @@ -373,14 +373,14 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1', 'The primary record post:1 was fetched by the correct url'); assert.strictEqual(post.id, '1', 'Stores record using the correct id'); assert.strictEqual(post.title, 'Ember.js rocks', 'Sets correct title to record'); - let author = await post.author; + const author = await post.author; assert.strictEqual(passedUrl[1], '/users/2', 'The relationship user:2 was fetched by the correct url'); assert.strictEqual(author.id, '2', 'Record has correct id'); @@ -419,7 +419,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let user = await store.findRecord('user', '1'); + const user = await store.findRecord('user', '1'); assert.strictEqual(passedUrl[0], '/users/1', 'The primary record user:1 was fetched by the correct url'); @@ -427,7 +427,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) assert.strictEqual(user.firstName, 'Yehuda', 'Sets correct firstName to record'); assert.strictEqual(user.lastName, 'Katz', 'Sets correct lastName to record'); - let company = await user.company; + const company = await user.company; assert.strictEqual( passedUrl[1], @@ -470,14 +470,14 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1', 'The primary record post:1 was fetched by the correct url'); assert.strictEqual(post.id, '1', 'Record has correct id'); assert.strictEqual(post.title, 'Ember.js rocks', 'Title is set correctly'); - let author = await post.author; + const author = await post.author; assert.strictEqual(passedUrl.length, 1); @@ -526,13 +526,13 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1'); assert.strictEqual(post.id, '1'); assert.strictEqual(post.title, 'Ember.js rocks'); - let comments = await post.comments; + const comments = await post.comments; assert.strictEqual( passedUrl[1], @@ -585,13 +585,13 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1', 'The primary record post:1 was fetched by the correct url'); assert.strictEqual(post.id, '1', 'Record id is correct'); assert.strictEqual(post.title, 'Ember.js rocks', 'Record title is correct'); - let comments = await post.comments; + const comments = await post.comments; assert.strictEqual(passedUrl[1], '/comments/2', 'Builds correct URL to fetch related record'); assert.strictEqual(passedUrl[2], '/comments/3', 'Builds correct URL to fetch related record'); @@ -642,7 +642,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let user = await store.findRecord('user', '1'); + const user = await store.findRecord('user', '1'); assert.strictEqual(passedUrl[0], '/users/1', 'The primary record users:1 was fetched by the correct url'); @@ -650,7 +650,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) assert.strictEqual(user.firstName, 'Yehuda', 'Record firstName is loaded'); assert.strictEqual(user.lastName, 'Katz', 'Record lastName is loaded'); - let handles = await user.handles; + const handles = await user.handles; assert.strictEqual(passedUrl[1], '/github-handles/2', 'Builds correct URL to fetch related record'); assert.strictEqual(passedUrl[2], '/twitter-handles/3', 'Builds correct URL to fetch related record'); @@ -699,13 +699,13 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1', 'The primary record post:1 was fetched by the correct url'); assert.strictEqual(post.id, '1', 'Record id is loaded'); assert.strictEqual(post.title, 'Ember.js rocks', 'Record title is loaded'); - let comments = await post.comments; + const comments = await post.comments; assert.strictEqual(passedUrl.length, 1, 'Do not call extra end points because related records are included'); @@ -754,7 +754,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let user = await store.findRecord('user', '1'); + const user = await store.findRecord('user', '1'); assert.strictEqual(passedUrl[0], '/users/1'); @@ -762,7 +762,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) assert.strictEqual(user.firstName, 'Yehuda'); assert.strictEqual(user.lastName, 'Katz'); - let handles = await user.handles; + const handles = await user.handles; assert.strictEqual(passedUrl.length, 1, 'Do not call extra end points because related records are included'); @@ -791,7 +791,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let company = store.push({ + const company = store.push({ data: { type: 'company', id: '1', @@ -801,7 +801,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, }); - let githubHandle = store.push({ + const githubHandle = store.push({ data: { type: 'github-handle', id: '2', @@ -810,7 +810,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, }, }); - let twitterHandle = store.push({ + const twitterHandle = store.push({ data: { type: 'twitter-handle', id: '2', @@ -820,13 +820,13 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, }); - let user = store.createRecord('user', { + const user = store.createRecord('user', { firstName: 'Yehuda', lastName: 'Katz', company: company, }); - let handles = await user.handles; + const handles = await user.handles; handles.push(githubHandle); handles.push(twitterHandle); @@ -882,7 +882,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -893,7 +893,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, }); - let company = store.push({ + const company = store.push({ data: { type: 'company', id: '2', @@ -903,7 +903,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, }); - let githubHandle = store.push({ + const githubHandle = store.push({ data: { type: 'github-handle', id: '3', @@ -916,7 +916,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) user.set('firstName', 'Yehuda!'); user.set('company', company); - let handles = await user.handles; + const handles = await user.handles; handles.push(githubHandle); @@ -968,7 +968,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) } ); - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -979,7 +979,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, }); - let githubHandle = store.push({ + const githubHandle = store.push({ data: { type: 'github-handle', id: '2', @@ -989,7 +989,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, }); - let twitterHandle = store.push({ + const twitterHandle = store.push({ data: { type: 'twitter-handle', id: '3', @@ -1001,7 +1001,7 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) user.set('firstName', 'Yehuda!'); - let handles = await user.handles; + const handles = await user.handles; handles.push(githubHandle); handles.push(twitterHandle); @@ -1058,11 +1058,11 @@ module('integration/adapter/json-api-adapter - JSONAPIAdapter', function (hooks) }, ]); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); assert.strictEqual(passedUrl[0], '/posts/1'); - let author = await post.author; + const author = await post.author; assert.strictEqual(passedUrl[1], 'http://example.com/post/1/author'); assert.strictEqual(author, null); diff --git a/tests/main/tests/integration/adapter/queries-test.js b/tests/main/tests/integration/adapter/queries-test.js index e1901195317..e460bab87e4 100644 --- a/tests/main/tests/integration/adapter/queries-test.js +++ b/tests/main/tests/integration/adapter/queries-test.js @@ -22,7 +22,7 @@ module('integration/adapter/queries - Queries', function (hooks) { this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.expectAssertion(() => { store.query(); @@ -34,7 +34,7 @@ module('integration/adapter/queries - Queries', function (hooks) { this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.expectAssertion(() => { store.query('person'); @@ -48,8 +48,8 @@ module('integration/adapter/queries - Queries', function (hooks) { this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.query = function (store, type, query, recordArray) { assert.strictEqual(type, Person, 'the query method is called with the correct type'); @@ -74,7 +74,7 @@ module('integration/adapter/queries - Queries', function (hooks) { }); }; - let queryResults = await store.query('person', { page: '1' }); + const queryResults = await store.query('person', { page: '1' }); assert.strictEqual(queryResults.length, 2, 'the record array has a length of 2 after the results are loaded'); assert.true(queryResults.isLoaded, "the record array's `isLoaded` property should be true"); @@ -90,14 +90,14 @@ module('integration/adapter/queries - Queries', function (hooks) { this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.query = function () { return Promise.resolve({ data: [{ id: 'first', type: 'person' }] }); }; - let personsQuery = await store.query('person', {}); + const personsQuery = await store.query('person', {}); assert.strictEqual(personsQuery.length, 1, 'There is one person'); assert.strictEqual(personsQuery.at(0).id, 'first', 'the right person is present'); @@ -139,8 +139,8 @@ module('integration/adapter/queries - Queries', function (hooks) { this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.query = function (store, type, query, recordArray) { assert.strictEqual(type, Person, 'the query method is called with the correct type'); diff --git a/tests/main/tests/integration/adapter/record-persistence-test.js b/tests/main/tests/integration/adapter/record-persistence-test.js index 31f1b7d762d..faa96d35110 100644 --- a/tests/main/tests/integration/adapter/record-persistence-test.js +++ b/tests/main/tests/integration/adapter/record-persistence-test.js @@ -27,8 +27,8 @@ module('integration/adapter/record_persistence - Persisting Records', function ( this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.updateRecord = function (_store, type, snapshot) { assert.strictEqual(type, Person, "The type of the record is 'Person'"); @@ -71,9 +71,10 @@ module('integration/adapter/record_persistence - Persisting Records', function ( this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + // eslint-disable-next-line prefer-const let tom; adapter.createRecord = function (_store, type, snapshot) { @@ -107,8 +108,8 @@ module('integration/adapter/record_persistence - Persisting Records', function ( this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let tom; @@ -119,7 +120,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( tom = store.createRecord('person', { name: 'Tom Dale' }); tom = await tom.save(); - let retrievedTom = await store.findRecord('person', '1'); + const retrievedTom = await store.findRecord('person', '1'); assert.strictEqual(tom, retrievedTom, 'The retrieved record is the same as the created record'); }); @@ -141,8 +142,8 @@ module('integration/adapter/record_persistence - Persisting Records', function ( this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function (_store, type, snapshot) { assert.strictEqual(type, Person, "The type of the record is 'Person'"); @@ -161,7 +162,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( }, }); - let tom = await store.findRecord('person', '1'); + const tom = await store.findRecord('person', '1'); tom.deleteRecord(); @@ -187,8 +188,8 @@ module('integration/adapter/record_persistence - Persisting Records', function ( this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.updateRecord = function (_store, _type, snapshot) { if (snapshot.id === '1') { @@ -232,7 +233,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( ], }); - let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); + const [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); tom.set('name', 'Draaaaaahm Dale'); yehuda.set('name', 'Goy Katz'); @@ -240,7 +241,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( assert.true(tom.hasDirtyAttributes, 'Tom is dirty'); assert.true(yehuda.hasDirtyAttributes, 'Yehuda is dirty'); - let [{ value: savedTom }, { value: savedYehuda }] = await Promise.allSettled([tom.save(), yehuda.save()]); + const [{ value: savedTom }, { value: savedYehuda }] = await Promise.allSettled([tom.save(), yehuda.save()]); assert.strictEqual(savedTom, tom, 'The record is correct'); assert.strictEqual(savedYehuda, yehuda, 'The record is correct'); @@ -281,8 +282,8 @@ module('integration/adapter/record_persistence - Persisting Records', function ( this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = () => Promise.resolve(); @@ -305,7 +306,7 @@ module('integration/adapter/record_persistence - Persisting Records', function ( ], }); - let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); + const [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); assert.false(tom.isDeleted, 'Tom is not deleted'); assert.false(yehuda.isDeleted, 'Yehuda is not deleted'); @@ -343,9 +344,10 @@ module('integration/adapter/record_persistence - Persisting Records', function ( }) ); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + // eslint-disable-next-line prefer-const let tom; adapter.createRecord = function (_store, type, snapshot) { diff --git a/tests/main/tests/integration/adapter/rest-adapter-test.js b/tests/main/tests/integration/adapter/rest-adapter-test.js index 18e8a87ec03..2ead69a7594 100644 --- a/tests/main/tests/integration/adapter/rest-adapter-test.js +++ b/tests/main/tests/integration/adapter/rest-adapter-test.js @@ -91,12 +91,12 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }; adapter._ajaxRequest = (hash) => { - let jqXHR = { + const jqXHR = { status, responseText, getAllResponseHeaders() { - let reducer = (prev, key) => prev + key + ': ' + headers[key] + '\r\n'; - let stringify = (headers) => { + const reducer = (prev, key) => prev + key + ': ' + headers[key] + '\r\n'; + const stringify = (headers) => { return Object.keys(headers).reduce(reducer, ''); }; return stringify(headers); @@ -148,7 +148,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); ajaxResponse(); post.set('name', 'The Parley Letter'); @@ -187,7 +187,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse(); post.set('name', 'The Parley Letter'); @@ -217,7 +217,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ posts: [{ id: '1', name: 'Dat Parley Letter' }] }); post.set('name', 'The Parley Letter'); @@ -252,7 +252,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ post: { id: '1', name: 'Dat Parley Letter' } }); post.set('name', 'The Parley Letter'); @@ -276,13 +276,12 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { } this.owner.register('model:post', Post); - let post; ajaxResponse({ posts: [{ id: '1', name: 'Dat Parley Letter' }], comments: [{ id: '1', name: 'FIRST' }], }); - post = store.createRecord('post', { name: 'The Parley Letter' }); + const post = store.createRecord('post', { name: 'The Parley Letter' }); await post.save(); assert.strictEqual(passedUrl, '/posts', 'we pass the correct url'); assert.strictEqual(passedVerb, 'POST', 'we pass the correct http method'); @@ -292,11 +291,11 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { assert.false(post.hasDirtyAttributes, "the post isn't dirty anymore"); assert.strictEqual(post.name, 'Dat Parley Letter', 'the post was updated'); - let comment = store.peekRecord('comment', '1'); + const comment = store.peekRecord('comment', '1'); assert.strictEqual(comment.name, 'FIRST', 'The comment was sideloaded'); }); - test('updateRecord - a payload with sideloaded updates pushes the updates', async function (assert) { + test('updateRecord - a payload with sideloaded updates pushes the updates, v2', async function (assert) { class Comment extends Model { @attr name; } @@ -318,7 +317,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ posts: [{ id: '1', name: 'Dat Parley Letter' }], comments: [{ id: '1', name: 'FIRST' }], @@ -333,7 +332,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { assert.false(post.hasDirtyAttributes, "the post isn't dirty anymore"); assert.strictEqual(post.name, 'Dat Parley Letter', 'the post was updated'); - let comment = store.peekRecord('comment', 1); + const comment = store.peekRecord('comment', 1); assert.strictEqual(comment.name, 'FIRST', 'The comment was sideloaded'); }); @@ -370,7 +369,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ajaxResponse(); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); post.set('name', 'The Parley Letter'); await post.save(); @@ -428,9 +427,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }); await store.findRecord('comment', '2'); - let post = await store.findRecord('post', '1'); - let newComment = store.peekRecord('comment', '2'); - let comments = post.comments; + const post = await store.findRecord('post', '1'); + const newComment = store.peekRecord('comment', '2'); + const comments = post.comments; // Replace the comment with a new one comments.pop(); @@ -536,8 +535,8 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }); let post = await store.peekRecord('post', 1); - let comment = await store.peekRecord('comment', 1); - let comments = post.comments; + const comment = await store.peekRecord('comment', 1); + const comments = post.comments; comments.push(comment); assert.strictEqual(post.comments.length, 1, 'the post has one comment'); @@ -694,7 +693,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse(); post.deleteRecord(); @@ -735,7 +734,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse(); post.deleteRecord(); @@ -767,7 +766,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ comments: [{ id: '1', name: 'FIRST' }] }); post.deleteRecord(); @@ -780,7 +779,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { assert.false(post.hasDirtyAttributes, "the post isn't dirty anymore"); assert.true(post.isDeleted, 'the post is now deleted'); - let comment = store.peekRecord('comment', 1); + const comment = store.peekRecord('comment', 1); assert.strictEqual(comment.name, 'FIRST', 'The comment was sideloaded'); }); @@ -807,7 +806,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ posts: [{ id: '2', name: 'The Parley Letter' }] }); post.deleteRecord(); @@ -820,7 +819,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { assert.false(post.hasDirtyAttributes, "the original post isn't dirty anymore"); assert.true(post.isDeleted, 'the original post is now deleted'); - let newPost = store.peekRecord('post', 2); + const newPost = store.peekRecord('post', 2); assert.strictEqual(newPost.name, 'The Parley Letter', 'The new post was added to the store'); }); @@ -836,8 +835,8 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { } this.owner.register('model:comment', Comment); - let post = store.createRecord('post'); - let identifier = recordIdentifierFor(post); + const post = store.createRecord('post'); + const identifier = recordIdentifierFor(post); post.deleteRecord(); await post.save(); @@ -871,13 +870,13 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let posts = await store.findAll('post'); + const posts = await store.findAll('post'); assert.strictEqual(passedUrl, '/posts'); assert.strictEqual(passedVerb, 'GET'); assert.deepEqual(passedHash.data, {}); - let post1 = store.peekRecord('post', 1); - let post2 = store.peekRecord('post', 2); + const post1 = store.peekRecord('post', 1); + const post2 = store.peekRecord('post', 2); assert.deepEqual(post1.getProperties('id', 'name'), { id: '1', name: 'Rails is omakase' }, 'Post 1 is loaded'); @@ -901,7 +900,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { this.owner.register('model:comment', Comment); assert.expect(2); - let adapterOptionsStub = { stub: true }; + const adapterOptionsStub = { stub: true }; adapter.buildURL = function (type, id, snapshot, requestType) { assert.strictEqual(snapshot.adapterOptions, adapterOptionsStub); return '/' + requestType + '/posts'; @@ -960,7 +959,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { await store.findAll('post'); - let comment = store.peekRecord('comment', '1'); + const comment = store.peekRecord('comment', '1'); assert.deepEqual(comment.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); }); @@ -991,9 +990,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let posts = await store.findAll('post'); - let post1 = store.peekRecord('post', 1); - let post2 = store.peekRecord('post', 2); + const posts = await store.findAll('post'); + const post1 = store.peekRecord('post', 1); + const post2 = store.peekRecord('post', 2); assert.deepEqual(post1.getProperties('id', 'name'), { id: '1', name: 'Rails is omakase' }, 'Post 1 is loaded'); assert.deepEqual(post2.getProperties('id', 'name'), { id: '2', name: 'The Parley Letter' }, 'Post 2 is loaded'); @@ -1094,9 +1093,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }); adapter.sortQueryParams = function (obj) { - let sortedKeys = Object.keys(obj).sort().reverse(); - let len = sortedKeys.length; - let newQueryParams = {}; + const sortedKeys = Object.keys(obj).sort().reverse(); + const len = sortedKeys.length; + const newQueryParams = {}; for (var i = 0; i < len; i++) { newQueryParams[sortedKeys[i]] = obj[sortedKeys[i]]; @@ -1129,7 +1128,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { posts: [{ id: '1', name: 'Rails is very expensive sushi' }], }); - let posts = await store.query('post', { page: 2 }); + const posts = await store.query('post', { page: 2 }); assert.strictEqual(posts.meta.offset, 5, 'Reponse metadata can be accessed with recordArray.meta'); }); @@ -1150,14 +1149,14 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { posts: [{ id: '1', name: 'Rails is very expensive sushi' }], }); - let posts = await store.query('post', { page: 2 }); + const posts = await store.query('post', { page: 2 }); assert.strictEqual(posts.meta.offset, 5, 'Reponse metadata can be accessed with recordArray.meta'); ajaxResponse({ meta: { offset: 1 }, posts: [{ id: '1', name: 'Rails is very expensive sushi' }], }); - let newPosts = await store.query('post', { page: 1 }); + const newPosts = await store.query('post', { page: 1 }); assert.strictEqual(newPosts.meta.offset, 1, 'new array has correct metadata'); assert.strictEqual(posts.meta.offset, 5, 'metadata on the old array hasnt been clobbered'); }); @@ -1181,13 +1180,13 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let posts = await store.query('post', { page: 1 }); + const posts = await store.query('post', { page: 1 }); assert.strictEqual(passedUrl, '/posts'); assert.strictEqual(passedVerb, 'GET'); assert.deepEqual(passedHash.data, { page: 1 }); - let post1 = store.peekRecord('post', 1); - let post2 = store.peekRecord('post', 2); + const post1 = store.peekRecord('post', 1); + const post2 = store.peekRecord('post', 2); assert.deepEqual(post1.getProperties('id', 'name'), { id: '1', name: 'Rails is omakase' }, 'Post 1 is loaded'); assert.deepEqual(post2.getProperties('id', 'name'), { id: '2', name: 'The Parley Letter' }, 'Post 2 is loaded'); @@ -1218,7 +1217,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }); await store.query('post', { page: 1 }); - let comment = store.peekRecord('comment', 1); + const comment = store.peekRecord('comment', 1); assert.deepEqual(comment.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); }); @@ -1250,9 +1249,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let posts = await store.query('post', { page: 1 }); - let post1 = store.peekRecord('post', 1); - let post2 = store.peekRecord('post', 2); + const posts = await store.query('post', { page: 1 }); + const post1 = store.peekRecord('post', 1); + const post2 = store.peekRecord('post', 2); assert.deepEqual(post1.getProperties('id', 'name'), { id: '1', name: 'Rails is omakase' }, 'Post 1 is loaded'); @@ -1277,7 +1276,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ajaxResponse({}); - let post = await store.queryRecord('post', { slug: 'ember-js-rocks' }); + const post = await store.queryRecord('post', { slug: 'ember-js-rocks' }); assert.strictEqual(post, null); }); @@ -1297,7 +1296,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { post: null, }); - let post = await store.queryRecord('post', { slug: 'ember-js-rocks' }); + const post = await store.queryRecord('post', { slug: 'ember-js-rocks' }); assert.strictEqual(post, null); }); @@ -1320,7 +1319,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.queryRecord('post', { slug: 'ember-js-rocks' }); + const post = await store.queryRecord('post', { slug: 'ember-js-rocks' }); assert.deepEqual(post.name, 'Ember.js rocks'); }); @@ -1342,7 +1341,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }); await store.queryRecord('post', { slug: 'rails-is-omakaze' }); - let comment = store.peekRecord('comment', 1); + const comment = store.peekRecord('comment', 1); assert.deepEqual(comment.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); }); @@ -1459,7 +1458,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); ajaxResponse({ comments: [ { id: '1', name: 'FIRST' }, @@ -1511,7 +1510,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); ajaxResponse({ comments: [ { id: '1', name: 'FIRST' }, @@ -1555,7 +1554,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); //It's still ok to return this even without coalescing because RESTSerializer supports sideloading ajaxResponse({ comments: [ @@ -1604,7 +1603,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ comments: [ { id: '1', name: 'FIRST' }, @@ -1613,10 +1612,10 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let comments = await post.comments; - let comment1 = store.peekRecord('comment', 1); - let comment2 = store.peekRecord('comment', 2); - let comment3 = store.peekRecord('comment', 3); + const comments = await post.comments; + const comment1 = store.peekRecord('comment', 1); + const comment2 = store.peekRecord('comment', 2); + const comment3 = store.peekRecord('comment', 3); assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); assert.deepEqual(comment2.getProperties('id', 'name'), { id: '2', name: 'Rails is unagi' }); @@ -1671,13 +1670,13 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { posts: [{ id: '2', name: 'The Parley Letter' }], }); - let comments = await post.comments; + const comments = await post.comments; - let comment1 = store.peekRecord('comment', '1'); - let comment2 = store.peekRecord('comment', '2'); - let comment3 = store.peekRecord('comment', '3'); - let comment4 = store.peekRecord('comment', '4'); - let post2 = store.peekRecord('post', '2'); + const comment1 = store.peekRecord('comment', '1'); + const comment2 = store.peekRecord('comment', '2'); + const comment3 = store.peekRecord('comment', '3'); + const comment4 = store.peekRecord('comment', '4'); + const post2 = store.peekRecord('post', '2'); assert.deepEqual(comments.slice(), [comment1, comment2, comment3], 'The correct records are in the array'); @@ -1738,7 +1737,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ comments: [ @@ -1748,10 +1747,10 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let comments = await post.comments; - let comment1 = store.peekRecord('comment', 1); - let comment2 = store.peekRecord('comment', 2); - let comment3 = store.peekRecord('comment', 3); + const comments = await post.comments; + const comment1 = store.peekRecord('comment', 1); + const comment2 = store.peekRecord('comment', 2); + const comment3 = store.peekRecord('comment', 3); assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); assert.deepEqual(comment2.getProperties('id', 'name'), { id: '2', name: 'Rails is unagi' }); @@ -1793,7 +1792,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); ajaxResponse({ comments: [ @@ -1803,14 +1802,14 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let comments = await post.comments; + const comments = await post.comments; assert.strictEqual(passedUrl, '/posts/1/comments'); assert.strictEqual(passedVerb, 'GET'); assert.strictEqual(passedHash, undefined); - let comment1 = store.peekRecord('comment', 1); - let comment2 = store.peekRecord('comment', 2); - let comment3 = store.peekRecord('comment', 3); + const comment1 = store.peekRecord('comment', 1); + const comment2 = store.peekRecord('comment', 2); + const comment3 = store.peekRecord('comment', 3); assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); assert.deepEqual(comment2.getProperties('id', 'name'), { @@ -1861,7 +1860,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); ajaxResponse({ comments: [ @@ -1906,7 +1905,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); ajaxResponse({ comments: [ @@ -1917,18 +1916,18 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { posts: [{ id: '2', name: 'The Parley Letter' }], }); - let comments = await post.comments; - let comment1 = store.peekRecord('comment', 1); - let comment2 = store.peekRecord('comment', 2); - let comment3 = store.peekRecord('comment', 3); - let post2 = store.peekRecord('post', 2); + const comments = await post.comments; + const comment1 = store.peekRecord('comment', 1); + const comment2 = store.peekRecord('comment', 2); + const comment3 = store.peekRecord('comment', 3); + const post2 = store.peekRecord('post', 2); assert.deepEqual(comments.slice(), [comment1, comment2, comment3], 'The correct records are in the array'); assert.deepEqual(post2.getProperties('id', 'name'), { id: '2', name: 'The Parley Letter' }); }); - test('findMany - a custom serializer is used if present', async function (assert) { + test('findMany - a custom serializer is used if present, v2', async function (assert) { adapter.shouldBackgroundReloadRecord = () => false; this.owner.register( 'serializer:post', @@ -1987,9 +1986,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return post.comments; }) .then((comments) => { - let comment1 = store.peekRecord('comment', 1); - let comment2 = store.peekRecord('comment', 2); - let comment3 = store.peekRecord('comment', 3); + const comment1 = store.peekRecord('comment', 1); + const comment2 = store.peekRecord('comment', 2); + const comment3 = store.peekRecord('comment', 3); assert.deepEqual(comment1.getProperties('id', 'name'), { id: '1', name: 'FIRST' }); assert.deepEqual(comment2.getProperties('id', 'name'), { id: '2', name: 'Rails is unagi' }); @@ -2038,7 +2037,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let comment = await store.findRecord('comment', '1'); + const comment = await store.findRecord('comment', '1'); ajaxResponse({ post: { id: '1', name: 'Rails is omakase' } }); await comment.post; }); @@ -2064,7 +2063,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { comments: [{ id: '1', type: 'comment' }], }); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '2', @@ -2143,7 +2142,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = store.peekRecord('post', 2); + const post = store.peekRecord('post', 2); await post.comments; }); @@ -2195,7 +2194,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - let post = store.peekRecord('post', 2); + const post = store.peekRecord('post', 2); await post.comments; }); @@ -2230,10 +2229,10 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { keyForRelationship(rel, kind) { if (kind === 'belongsTo') { - let underscored = underscore(rel); + const underscored = underscore(rel); return underscored + '_id'; } else { - let singular = singularize(rel); + const singular = singularize(rel); return underscore(singular) + '_ids'; } }, @@ -2270,7 +2269,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let post = await store.findRecord('post', 1); + const post = await store.findRecord('post', 1); assert.strictEqual(post.authorName, '@d2h'); assert.strictEqual(post.author.name, 'D2H'); assert.deepEqual( @@ -2296,9 +2295,8 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return new Array(n + 1).join(character); } - let a2000 = repeatChar('a', 2000); - let b2000 = repeatChar('b', 2000); - let post; + const a2000 = repeatChar('a', 2000); + const b2000 = repeatChar('b', 2000); store.push({ data: { @@ -2315,7 +2313,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); adapter.coalesceFindRequests = true; @@ -2353,9 +2351,8 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return new Array(n + 1).join(character); } - let a100 = repeatChar('a', 100); - let b100 = repeatChar('b', 100); - let post; + const a100 = repeatChar('a', 100); + const b100 = repeatChar('b', 100); store.push({ data: { @@ -2372,7 +2369,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { }, }); - post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); adapter.coalesceFindRequests = true; @@ -2403,7 +2400,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { assert.expect(2); - let data = { + const data = { post: { id: '1', name: 'Docker is amazing', @@ -2436,9 +2433,9 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { this.owner.register('model:comment', Comment); assert.expect(4); - let responseText = 'Nope lol'; + const responseText = 'Nope lol'; - let expectedRequestData = { + const expectedRequestData = { method: 'GET', url: '/posts/1', }; @@ -2475,7 +2472,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { assert.expect(4); - let data = { + const data = { something: 'is invalid', }; @@ -2579,7 +2576,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { } catch (err) { assert.ok(err instanceof AbortError, 'reason should be an instance of AbortError'); assert.strictEqual(err.errors.length, 1, 'AbortError includes errors with request/response details'); - let expectedError = { + const expectedError = { title: 'Adapter Error', detail: 'Request failed: GET /posts/1', status: 0, @@ -2601,14 +2598,14 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { } this.owner.register('model:comment', Comment); - let jqXHR = { + const jqXHR = { responseText: 'Nope lol', getAllResponseHeaders() { return ''; }, }; - let errorThrown = new Error('nope!'); + const errorThrown = new Error('nope!'); adapter.useFetch = false; adapter._ajaxRequest = function (hash) { @@ -2643,14 +2640,14 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { } this.owner.register('model:comment', Comment); - let jqXHR = { + const jqXHR = { responseText: '', getAllResponseHeaders() { return ''; }, }; - let errorThrown = 'nope!'; + const errorThrown = 'nope!'; adapter.useFetch = false; adapter._ajaxRequest = function (hash) { @@ -2808,7 +2805,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let posts = await store.findAll('post'); + const posts = await store.findAll('post'); assert.strictEqual(get(posts, 'length'), 3); posts.forEach((post) => assert.ok(post instanceof Model)); }); @@ -2843,10 +2840,10 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { ], }); - let post = store.createRecord('post', { name: 'The Parley Letter' }); + const post = store.createRecord('post', { name: 'The Parley Letter' }); await post.save(); - let comments = store.peekAll('comment'); + const comments = store.peekAll('comment'); assert.strictEqual(comments.length, 2, 'comments.length is correct'); assert.strictEqual(comments[0].name, 'First comment', 'comments.at(0).name is correct'); @@ -2873,7 +2870,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return [201, { 'Content-Type': 'application/json' }, '']; }); - let post = store.createRecord('post'); + const post = store.createRecord('post'); return post.save().then( () => { assert.strictEqual(true, false, 'should not have fulfilled'); @@ -2906,7 +2903,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return [201, { 'Content-Type': 'application/json' }, '']; }); - let post = store.createRecord('post'); + const post = store.createRecord('post'); return post.save().then( () => { assert.equal(true, false, 'should not have fulfilled'); @@ -2938,7 +2935,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return [200, { 'Content-Type': 'application/json' }, '']; }); - let post = store.push({ data: { id: '1', type: 'post' } }); + const post = store.push({ data: { id: '1', type: 'post' } }); await assert.expectWarning(async () => { return post.save().then(() => assert.ok(true, 'save fullfills correctly')); }, /JSON/); @@ -2963,7 +2960,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return [200, { 'Content-Type': 'application/json' }, '']; }); - let post = store.push({ data: { id: '1', type: 'post' } }); + const post = store.push({ data: { id: '1', type: 'post' } }); return post.save().then(() => assert.ok(true, 'save fullfills correctly')); }); @@ -2985,7 +2982,7 @@ module('integration/adapter/rest_adapter - REST Adapter', function (hooks) { return [200, { 'Content-Type': 'application/json' }, null]; }); - let post = store.push({ data: { id: '1', type: 'post' } }); + const post = store.push({ data: { id: '1', type: 'post' } }); return post.save().then(() => assert.ok(true, 'save fullfills correctly')); }); }); diff --git a/tests/main/tests/integration/adapter/rest-adapter/create-record-test.js b/tests/main/tests/integration/adapter/rest-adapter/create-record-test.js index 29894cd97d8..9c0c769a653 100644 --- a/tests/main/tests/integration/adapter/rest-adapter/create-record-test.js +++ b/tests/main/tests/integration/adapter/rest-adapter/create-record-test.js @@ -479,7 +479,7 @@ module('integration/adapter/rest_adapter - REST Adapter - createRecord', functio const commentCount = post.comments.length; assert.strictEqual(commentCount, 1, 'the post starts life with a comment'); - let comment = store.createRecord('comment', { name: 'Another Comment', post: post }); + const comment = store.createRecord('comment', { name: 'Another Comment', post: post }); await comment.save(); assert.strictEqual(comment.post, post, 'the comment is related to the post'); diff --git a/tests/main/tests/integration/adapter/rest-adapter/find-record-test.js b/tests/main/tests/integration/adapter/rest-adapter/find-record-test.js index 294b3865afd..24580a4704f 100644 --- a/tests/main/tests/integration/adapter/rest-adapter/find-record-test.js +++ b/tests/main/tests/integration/adapter/rest-adapter/find-record-test.js @@ -86,7 +86,7 @@ module('integration/adapter/rest_adapter - REST Adapter - findRecord', function this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let id = '1'; + const id = '1'; const store = this.owner.lookup('service:store'); const adapter = store.adapterFor('application'); const ajaxCallback = ajaxResponse(adapter, { posts: [{ id, name: 'Rails is omakase' }] }); @@ -120,10 +120,10 @@ module('integration/adapter/rest_adapter - REST Adapter - findRecord', function assert.strictEqual(post.name, 'Rails is omakase'); // stress tests - let peekPost = store.peekRecord(findRecordArgs); + const peekPost = store.peekRecord(findRecordArgs); assert.strictEqual(peekPost, post, 'peekRecord returns same post'); - let recordReference = store.getReference(findRecordArgs); + const recordReference = store.getReference(findRecordArgs); assert.strictEqual(recordReference.remoteType(), 'identity'); assert.strictEqual(recordReference.type, 'post'); assert.strictEqual(recordReference.id(), '1'); @@ -147,10 +147,10 @@ module('integration/adapter/rest_adapter - REST Adapter - findRecord', function assert.strictEqual(record, foundPost, 'We were able to findRecord'); // stress tests - let peekPost = store.peekRecord(identifier); + const peekPost = store.peekRecord(identifier); assert.strictEqual(peekPost, foundPost, 'peekRecord returns same post'); - let recordReference = store.getReference(identifier); + const recordReference = store.getReference(identifier); assert.strictEqual(recordReference.remoteType(), 'identity'); assert.strictEqual(recordReference.type, 'post'); assert.strictEqual(recordReference.id(), null); diff --git a/tests/main/tests/integration/adapter/serialize-test.js b/tests/main/tests/integration/adapter/serialize-test.js index a16553ab9aa..d88f7714bd2 100644 --- a/tests/main/tests/integration/adapter/serialize-test.js +++ b/tests/main/tests/integration/adapter/serialize-test.js @@ -18,16 +18,16 @@ module('integration/adapter/serialize - DS.Adapter integration test', function ( this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const serializer = store.serializerFor('application'); serializer.serialize = function (snapshot, options) { assert.deepEqual(options, { foo: 'bar' }); return {}; }; - let person = store.createRecord('person'); + const person = store.createRecord('person'); adapter.serialize(person._createSnapshot(), { foo: 'bar' }); }); diff --git a/tests/main/tests/integration/adapter/store-adapter-test.js b/tests/main/tests/integration/adapter/store-adapter-test.js index 3d6c4ef66a4..df76de13f06 100644 --- a/tests/main/tests/integration/adapter/store-adapter-test.js +++ b/tests/main/tests/integration/adapter/store-adapter-test.js @@ -17,11 +17,11 @@ import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in function moveRecordOutOfInFlight(record) { // move record out of the inflight state so the tests can clean up // correctly - let { store } = record; - let identifier = recordIdentifierFor(record); + const { store } = record; + const identifier = recordIdentifierFor(record); // TODO this would be made nicer by a cancellation API - let pending = store.getRequestStateService().getPendingRequestsForRecord(identifier); + const pending = store.getRequestStateService().getPendingRequestsForRecord(identifier); pending.splice(0, pending.length); } @@ -45,8 +45,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('Records loaded multiple times and retrieved in recordArray are ready to send state events', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.query = function (store, type, query, recordArray) { return Promise.resolve({ @@ -82,9 +82,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('by default, createRecords calls createRecord once per record', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); let count = 1; adapter.shouldBackgroundReloadRecord = () => false; @@ -99,8 +99,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.ok(false, 'should not have invoked more than 2 times'); } - let hash = snapshot.attributes(); - let recordId = count; + const hash = snapshot.attributes(); + const recordId = count; hash['updated-at'] = 'now'; count++; @@ -133,9 +133,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('by default, updateRecords calls updateRecord once per record', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); let count = 0; adapter.shouldBackgroundReloadRecord = () => false; @@ -176,12 +176,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ], }); - let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); + const [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); set(tom, 'name', 'Tom Dale'); set(yehuda, 'name', 'Yehuda Katz'); - let [tom2, yehuda2] = await Promise.all([tom.save(), yehuda.save()]); + const [tom2, yehuda2] = await Promise.all([tom.save(), yehuda.save()]); assert.false(tom2.isSaving, 'record is no longer saving'); assert.true(tom2.isLoaded, 'record is loaded'); @@ -191,9 +191,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('additional new values can be returned on store save', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); let count = 0; adapter.shouldBackgroundReloadRecord = () => false; @@ -257,9 +257,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('by default, deleteRecord calls deleteRecord once per record', async function (assert) { assert.expect(4); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); let count = 0; adapter.shouldBackgroundReloadRecord = () => false; @@ -298,7 +298,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ], }); - let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); + const [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); tom.deleteRecord(); yehuda.deleteRecord(); @@ -309,9 +309,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('by default, destroyRecord calls deleteRecord once per record without requiring .save', async function (assert) { assert.expect(4); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); let count = 0; @@ -351,7 +351,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration ], }); - let [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); + const [tom, yehuda] = await Promise.all([store.findRecord('person', '1'), store.findRecord('person', '2')]); await Promise.all([tom.destroyRecord(), yehuda.destroyRecord()]); }); @@ -359,8 +359,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('if an existing model is edited then deleted, deleteRecord is called on the adapter', async function (assert) { assert.expect(5); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let count = 0; adapter.shouldBackgroundReloadRecord = () => false; @@ -400,11 +400,11 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('if a deleted record errors, it enters the error state', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let count = 0; - let error = new AdapterError(); + const error = new AdapterError(); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function (store, type, snapshot) { @@ -443,9 +443,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('if a created record is marked as invalid by the server, it enters an error state', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); adapter.createRecord = function (store, type, snapshot) { assert.strictEqual(type, Person, 'the type is correct'); @@ -467,7 +467,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration } }; - let yehuda = store.createRecord('person', { id: '1', name: 'Yehuda Katz' }); + const yehuda = store.createRecord('person', { id: '1', name: 'Yehuda Katz' }); // Wrap this in an Ember.run so that all chained async behavior is set up // before flushing any scheduled behavior. @@ -488,7 +488,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.true(yehuda.isNew, 'precond - record is still new'); - let person = await yehuda.save(); + const person = await yehuda.save(); assert.strictEqual(person, yehuda, 'The promise resolves with the saved record'); @@ -498,8 +498,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('allows errors on arbitrary properties on create', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function (store, type, snapshot) { if (snapshot.attr('name').indexOf('Bro') === -1) { @@ -519,12 +519,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration } }; - let yehuda = store.createRecord('person', { id: '1', name: 'Yehuda Katz' }); + const yehuda = store.createRecord('person', { id: '1', name: 'Yehuda Katz' }); // Wrap this in an Ember.run so that all chained async behavior is set up // before flushing any scheduled behavior. - let person = await yehuda.save().catch(() => { + const person = await yehuda.save().catch(() => { assert.false(yehuda.isValid, 'the record is invalid'); assert.ok(get(yehuda, 'errors.base'), 'The errors.base property exists'); assert.deepEqual(get(yehuda, 'errors').errorsFor('base'), [ @@ -552,9 +552,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('if a created record is marked as invalid by the server, you can attempt the save again', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); let saveCount = 0; adapter.createRecord = function (store, type, snapshot) { @@ -578,12 +578,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration } }; - let yehuda = store.createRecord('person', { id: '1', name: 'Yehuda Katz' }); + const yehuda = store.createRecord('person', { id: '1', name: 'Yehuda Katz' }); // Wrap this in an Ember.run so that all chained async behavior is set up // before flushing any scheduled behavior. - let person = await yehuda + const person = await yehuda .save() .catch((reason) => { assert.strictEqual(saveCount, 1, 'The record has been saved once'); @@ -618,16 +618,16 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('if a created record is marked as erred by the server, it enters an error state', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let error = new AdapterError(); + const error = new AdapterError(); adapter.createRecord = function (store, type, snapshot) { return Promise.reject(error); }; - let person = store.createRecord('person', { id: '1', name: 'John Doe' }); + const person = store.createRecord('person', { id: '1', name: 'John Doe' }); return person.save().catch(() => { assert.ok(person.isError, 'the record is in the error state'); @@ -636,9 +636,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('if an updated record is marked as invalid by the server, it enters an error state', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function (store, type, snapshot) { @@ -661,7 +661,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration } }; - let yehuda = store.push({ + const yehuda = store.push({ data: { type: 'person', id: '1', @@ -673,7 +673,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration store.peekRecord('person', '1'); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); assert.strictEqual(person, yehuda, 'The same object is passed through'); assert.true(yehuda.isValid, 'precond - the record is valid'); @@ -682,8 +682,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.true(yehuda.hasDirtyAttributes, 'the record is dirty'); - let reason = yehuda.save(); - let response = await reason.catch(() => { + const reason = yehuda.save(); + const response = await reason.catch(() => { assert.true(yehuda.hasDirtyAttributes, 'the record is still dirty'); assert.false(yehuda.isValid, 'the record is invalid'); @@ -701,8 +701,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('records can have errors on arbitrary properties after update', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function (store, type, snapshot) { @@ -723,7 +723,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration } }; - let yehuda = store.push({ + const yehuda = store.push({ data: { type: 'person', id: '1', @@ -734,7 +734,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); store.peekRecord('person', '1'); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); assert.strictEqual(person, yehuda, 'The same object is passed through'); @@ -744,8 +744,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.true(yehuda.hasDirtyAttributes, 'the record is dirty'); - let reason = yehuda.save(); - let response = await reason.catch(() => { + const reason = yehuda.save(); + const response = await reason.catch(() => { assert.true(yehuda.hasDirtyAttributes, 'the record is still dirty'); assert.false(yehuda.isValid, 'the record is invalid'); assert.ok(get(yehuda, 'errors.base'), 'The errors.base property exists'); @@ -772,9 +772,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('if an updated record is marked as invalid by the server, you can attempt the save again', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); let saveCount = 0; adapter.shouldBackgroundReloadRecord = () => false; @@ -798,7 +798,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration } }; - let yehuda = store.push({ + const yehuda = store.push({ data: { type: 'person', id: '1', @@ -809,7 +809,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); store.peekRecord('person', '1'); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); assert.strictEqual(person, yehuda, 'The same object is passed through'); assert.true(yehuda.isValid, 'precond - the record is valid'); @@ -818,8 +818,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration assert.true(yehuda.hasDirtyAttributes, 'the record is dirty'); - let reason = yehuda.save(); - let response = await reason + const reason = yehuda.save(); + const response = await reason .catch((reason) => { assert.strictEqual(saveCount, 1, 'The record has been saved once'); assert.ok( @@ -849,17 +849,17 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('if a updated record is marked as erred by the server, it enters an error state', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let error = new AdapterError(); + const error = new AdapterError(); adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function (store, type, snapshot) { return Promise.reject(error); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -870,11 +870,11 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); store.peekRecord('person', '1'); - let record = await store.findRecord('person', '1'); + const record = await store.findRecord('person', '1'); assert.strictEqual(record, person, 'The person was resolved'); person.set('name', 'Jonathan Doe'); - let reason = person.save(); + const reason = person.save(); reason.catch(() => { assert.ok(person.isError, 'the record is in the error state'); assert.strictEqual(person.adapterError, error, 'error object is exposed'); @@ -884,9 +884,9 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('can be created after the Store', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Person = store.modelFor('person'); adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(type, Person, 'the type is correct'); @@ -897,8 +897,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test('relationships returned via `commit` do not trigger additional findManys', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Person extends Model { @hasMany('dog', { async: false, inverse: null }) dogs; @@ -977,8 +977,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); test("relationships don't get reset if the links is the same", async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Person extends Model { @hasMany('dog', { async: true, inverse: null }) dogs; @@ -1012,11 +1012,11 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); - let tom = person; - let dogs = tom.dogs; - let record = await dogs; + const tom = person; + const dogs = tom.dogs; + const record = await dogs; assert.strictEqual(record.length, 1, 'The dogs are loaded'); store.push({ @@ -1036,14 +1036,14 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }); assert.strictEqual(typeof tom.dogs.then, 'function', 'dogs is a thenable'); - let record2 = await tom.dogs; + const record2 = await tom.dogs; assert.strictEqual(record2.length, 1, 'The same dogs are loaded'); }); test('async hasMany always returns a promise', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Person extends Model { @hasMany('dog', { async: true, inverse: null }) dogs; } @@ -1065,7 +1065,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); }; - let tom = store.createRecord('person', { name: 'Tom Dale' }); + const tom = store.createRecord('person', { name: 'Tom Dale' }); assert.strictEqual(typeof tom.dogs.then, 'function', 'dogs is a thenable before save'); @@ -1076,15 +1076,15 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('createRecord receives a snapshot', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function (store, type, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); return Promise.resolve(); }; - let record = store.createRecord('person', { name: 'Tom Dale', id: '1' }); + const record = store.createRecord('person', { name: 'Tom Dale', id: '1' }); await record.save(); }); @@ -1092,16 +1092,14 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('updateRecord receives a snapshot', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.updateRecord = function (store, type, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); return Promise.resolve(); }; - let person; - store.push({ data: { type: 'person', @@ -1111,7 +1109,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }, }); - person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); set(person, 'name', 'Tomster'); await person.save(); @@ -1120,16 +1118,14 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('deleteRecord receives a snapshot', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function (store, type, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); return Promise.resolve(); }; - let person; - store.push({ data: { type: 'person', @@ -1139,7 +1135,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }, }); - person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); person.deleteRecord(); await person.save(); @@ -1148,8 +1144,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('findRecord receives a snapshot', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); @@ -1162,8 +1158,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('findMany receives an array of snapshots', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Person extends Model { @hasMany('dog', { async: true, inverse: null }) dogs; } @@ -1182,8 +1178,6 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); }; - let person; - store.push({ data: { type: 'person', @@ -1198,7 +1192,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }, }); - person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); await person.dogs; }); @@ -1206,8 +1200,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('findHasMany receives a snapshot', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Person extends Model { @hasMany('dog', { async: true, inverse: null }) dogs; } @@ -1224,8 +1218,6 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }); }; - let person; - store.push({ data: { type: 'person', @@ -1239,7 +1231,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }, }); - person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); await person.dogs; }); @@ -1247,8 +1239,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('findBelongsTo receives a snapshot', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Person extends Model { @belongsTo('dog', { async: true, inverse: null }) dog; @@ -1261,8 +1253,6 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration return Promise.resolve({ data: { id: '2', type: 'dog' } }); }; - let person; - store.push({ data: { type: 'person', @@ -1276,7 +1266,7 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }, }); - person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); await person.dog; }); @@ -1284,8 +1274,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('record.save should pass adapterOptions to the updateRecord method', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.updateRecord = function (store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); @@ -1301,15 +1291,15 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }, }); - let person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); await person.save({ adapterOptions: { subscribe: true } }); }); test('record.save should pass adapterOptions to the createRecord method', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function (store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); @@ -1322,8 +1312,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('record.save should pass adapterOptions to the deleteRecord method', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function (store, type, snapshot) { assert.deepEqual(snapshot.adapterOptions, { subscribe: true }); @@ -1339,15 +1329,15 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration }, }, }); - let person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); await person.destroyRecord({ adapterOptions: { subscribe: true } }); }); test('store.findRecord should pass adapterOptions to adapter.findRecord', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { assert.deepEqual(snapshot.adapterOptions, { query: { embed: true } }); @@ -1360,8 +1350,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('store.query should pass adapterOptions to adapter.query ', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.query = function (store, type, query, array, options) { assert.notOk('adapterOptions' in query); @@ -1375,8 +1365,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('store.queryRecord should pass adapterOptions to adapter.queryRecord', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.queryRecord = function (store, type, query, snapshot) { assert.notOk('adapterOptions' in query); @@ -1390,8 +1380,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test("store.findRecord should pass 'include' to adapter.findRecord", async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = (store, type, id, snapshot) => { assert.strictEqual(snapshot.include, 'books', 'include passed to adapter.findRecord'); @@ -1404,11 +1394,11 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test('store.findAll should pass adapterOptions to the adapter.findAll method', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findAll = function (store, type, sinceToken, arraySnapshot) { - let adapterOptions = arraySnapshot.adapterOptions; + const adapterOptions = arraySnapshot.adapterOptions; assert.deepEqual(adapterOptions, { query: { embed: true } }); return Promise.resolve({ data: [{ id: '1', type: 'person' }] }); }; @@ -1419,8 +1409,8 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration test("store.findAll should pass 'include' to adapter.findAll", async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findAll = function (store, type, sinceToken, arraySnapshot) { assert.strictEqual(arraySnapshot.include, 'books', 'include passed to adapter.findAll'); @@ -1469,11 +1459,11 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let post = await store.findRecord('post', '1'); + const post = await store.findRecord('post', '1'); - let comments = await post.comments; + const comments = await post.comments; assert.strictEqual(comments.length, 3); }); @@ -1481,12 +1471,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration testInDebug( 'There should be a friendly error for if the adapter does not implement createRecord', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = null; - let tom = store.createRecord('person', { name: 'Tom Dale' }); + const tom = store.createRecord('person', { name: 'Tom Dale' }); await assert.expectAssertion(async () => { await tom.save(); @@ -1499,12 +1489,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration testInDebug( 'There should be a friendly error for if the adapter does not implement updateRecord', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.updateRecord = null; - let tom = store.push({ data: { type: 'person', id: '1' } }); + const tom = store.push({ data: { type: 'person', id: '1' } }); await assert.expectAssertion(async () => { await tom.save(); @@ -1517,12 +1507,12 @@ module('integration/adapter/store-adapter - DS.Store and DS.Adapter integration testInDebug( 'There should be a friendly error for if the adapter does not implement deleteRecord', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = null; - let tom = store.push({ data: { type: 'person', id: '1' } }); + const tom = store.push({ data: { type: 'person', id: '1' } }); await assert.expectAssertion(async () => { tom.deleteRecord(); diff --git a/tests/main/tests/integration/application-test.js b/tests/main/tests/integration/application-test.js index f0d642d95e5..35425b1f89b 100644 --- a/tests/main/tests/integration/application-test.js +++ b/tests/main/tests/integration/application-test.js @@ -16,7 +16,7 @@ module('integration/application - Injecting a Custom Store', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.unregister('service:store'); owner.register( @@ -43,20 +43,20 @@ module('integration/application - Injecting a Custom Store', function (hooks) { }); test('If a Store property exists on an Application, it should be instantiated.', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.true(store.isCustom, 'the custom store was instantiated'); }); test('If a store is instantiated, it should be made available to each controller.', async function (assert) { ['foo', 'baz', 'application'].forEach((type) => { - let controller = this.owner.lookup(`controller:${type}`); + const controller = this.owner.lookup(`controller:${type}`); assert.true(controller.store.isCustom, 'the custom store was injected'); }); }); test('The JSONAPIAdapter is the default adapter when no custom adapter is provided', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); assert.ok(adapter instanceof JSONAPIAdapter, 'default adapter should be the JSONAPIAdapter'); }); @@ -66,7 +66,7 @@ module('integration/application - Injecting the Default Store', function (hooks) setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('controller:foo', Controller.extend({ store: service() })); owner.register( @@ -86,12 +86,12 @@ module('integration/application - Injecting the Default Store', function (hooks) }); test('If a Store property exists on an Application, it should be instantiated.', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.ok(store instanceof Store, 'the store was instantiated'); }); test('If a store is instantiated, it should be made available to each controller.', async function (assert) { - let fooController = this.owner.lookup('controller:foo'); + const fooController = this.owner.lookup('controller:foo'); assert.ok(fooController.store instanceof Store, 'the store was injected'); }); }); @@ -100,7 +100,7 @@ module('integration/application - Using the store as a service', function (hooks setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('controller:foo', Controller.extend({ store: service() })); owner.register( @@ -122,14 +122,14 @@ module('integration/application - Using the store as a service', function (hooks }); test('The store can be injected as a service', async function (assert) { - let doodleService = this.owner.lookup('service:doodle'); + const doodleService = this.owner.lookup('service:doodle'); assert.ok(doodleService.store instanceof Store, 'the store can be used as a service'); }); test('There can be multiple store services', function (assert) { - let doodleService = this.owner.lookup('service:doodle'); - let store = doodleService.store; - let secondService = this.owner.lookup('service:second-store'); + const doodleService = this.owner.lookup('service:doodle'); + const store = doodleService.store; + const secondService = this.owner.lookup('service:second-store'); assert.ok(secondService instanceof Store, 'the store can be used as a service'); assert.notStrictEqual(store, secondService, 'the store can be used as a service'); @@ -187,7 +187,7 @@ module('integration/application - Attaching initializer', function (hooks) { await this.application.boot(); this.owner = this.application.buildInstance(); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.ok( store && store.isCustomStore, 'ember-data initializer does not overwrite the previous registered service store' diff --git a/tests/main/tests/integration/backwards-compat/non-dasherized-lookups-test.js b/tests/main/tests/integration/backwards-compat/non-dasherized-lookups-test.js index bc4c0be7106..2cf3f2589ba 100644 --- a/tests/main/tests/integration/backwards-compat/non-dasherized-lookups-test.js +++ b/tests/main/tests/integration/backwards-compat/non-dasherized-lookups-test.js @@ -38,7 +38,7 @@ module( async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.pushPayload('post-note', { data: { @@ -66,7 +66,7 @@ module( async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.pushPayload('post-note', { data: { @@ -129,7 +129,7 @@ module( async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.pushPayload('post-note', { data: { @@ -170,7 +170,7 @@ module( async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.pushPayload('long_model_name', { data: { diff --git a/tests/main/tests/integration/cache-handler/store-package-setup-test.ts b/tests/main/tests/integration/cache-handler/store-package-setup-test.ts index 5588a34d14e..ca8da5761df 100644 --- a/tests/main/tests/integration/cache-handler/store-package-setup-test.ts +++ b/tests/main/tests/integration/cache-handler/store-package-setup-test.ts @@ -1,31 +1,31 @@ import { inject as service } from '@ember/service'; -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import Cache from '@ember-data/json-api'; import { LegacyNetworkHandler } from '@ember-data/legacy-compat'; -import RequestManager, { StructuredDataDocument, StructuredErrorDocument } from '@ember-data/request'; +import type { StructuredDataDocument, StructuredErrorDocument } from '@ember-data/request'; +import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Future, NextFn } from '@ember-data/request/-private/types'; import Fetch from '@ember-data/request/fetch'; import Store, { CacheHandler, recordIdentifierFor } from '@ember-data/store'; import type { Document } from '@ember-data/store/-private/document'; import type { NotificationType } from '@ember-data/store/-private/managers/notification-manager'; -import { Collection } from '@ember-data/store/-private/record-arrays/identifier-array'; +import type { Collection } from '@ember-data/store/-private/record-arrays/identifier-array'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; import type { JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; import type { RecordInstance } from '@ember-data/store/-types/q/record-instance'; -import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier'; -import { +import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; +import type { StableDocumentIdentifier,StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; +import type { CollectionResourceDataDocument, ResourceDataDocument, SingleResourceDataDocument, } from '@warp-drive/core-types/spec/document'; import type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw'; -import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; type FakeRecord = { [key: string]: unknown; destroy: () => void }; @@ -67,7 +67,7 @@ class TestStore extends Store { const record: FakeRecord = { id, lid, type } as unknown as FakeRecord; Object.assign(record, (this.cache.peek(identifier) as JsonApiResource).attributes); - let token = this.notifications.subscribe( + const token = this.notifications.subscribe( identifier, (_: StableRecordIdentifier, kind: NotificationType, key?: string) => { if (kind === 'attributes' && key) { @@ -296,7 +296,7 @@ module('Store | CacheHandler - @ember-data/store', function (hooks) { const record: FakeRecord = { id, lid, type } as unknown as FakeRecord; Object.assign(record, (this.cache.peek(identifier) as JsonApiResource).attributes); - let token = this.notifications.subscribe( + const token = this.notifications.subscribe( identifier, (_: StableRecordIdentifier, kind: NotificationType, key?: string) => { if (kind === 'attributes' && key) { @@ -394,7 +394,7 @@ module('Store | CacheHandler - @ember-data/store', function (hooks) { const record: FakeRecord = { id, lid, type } as unknown as FakeRecord; Object.assign(record, (this.cache.peek(identifier) as JsonApiResource).attributes); - let token = this.notifications.subscribe( + const token = this.notifications.subscribe( identifier, (_: StableRecordIdentifier, kind: NotificationType, key?: string) => { if (kind === 'attributes' && key) { @@ -493,7 +493,7 @@ module('Store | CacheHandler - @ember-data/store', function (hooks) { const record: FakeRecord = { id, lid, type } as unknown as FakeRecord; Object.assign(record, (this.cache.peek(identifier) as JsonApiResource).attributes); - let token = this.notifications.subscribe( + const token = this.notifications.subscribe( identifier, (_: StableRecordIdentifier, kind: NotificationType, key?: string) => { if (kind === 'attributes' && key) { diff --git a/tests/main/tests/integration/client-id-generation-test.js b/tests/main/tests/integration/client-id-generation-test.js index 3f85cdf9dc2..a7833aaf62b 100644 --- a/tests/main/tests/integration/client-id-generation-test.js +++ b/tests/main/tests/integration/client-id-generation-test.js @@ -15,7 +15,7 @@ module('integration - Client Id Generation', function (hooks) { let adapter; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; class Comment extends Model { @attr() @@ -56,7 +56,7 @@ module('integration - Client Id Generation', function (hooks) { }; adapter.createRecord = function (store, modelClass, snapshot) { - let type = modelClass.modelName; + const type = modelClass.modelName; if (type === 'comment') { assert.strictEqual(snapshot.id, 'id-1', "Comment passed to `createRecord` has 'id-1' assigned"); @@ -77,8 +77,8 @@ module('integration - Client Id Generation', function (hooks) { } }; - let comment = store.createRecord('comment'); - let post = store.createRecord('post'); + const comment = store.createRecord('comment'); + const post = store.createRecord('post'); assert.strictEqual(get(comment, 'id'), 'id-1', "comment is assigned id 'id-1'"); assert.strictEqual(get(post, 'id'), 'id-2', "post is assigned id 'id-2'"); @@ -100,7 +100,7 @@ module('integration - Client Id Generation', function (hooks) { assert.expect(6); let idCount = 0; let id = 1; - let ids = [undefined, '']; + const ids = [undefined, '']; adapter.generateIdForRecord = function (passedStore, record) { assert.strictEqual(store, passedStore, 'store is the first parameter'); @@ -113,8 +113,8 @@ module('integration - Client Id Generation', function (hooks) { return Promise.resolve({ data: { id: id++, type: type.modelName } }); }; - let comment = store.createRecord('misc'); - let post = store.createRecord('misc'); + const comment = store.createRecord('misc'); + const post = store.createRecord('misc'); assert.strictEqual(get(comment, 'id'), null, "comment is assigned id 'null'"); assert.strictEqual(get(post, 'id'), null, "post is assigned id 'null'"); diff --git a/tests/main/tests/integration/identifiers/cache-test.ts b/tests/main/tests/integration/identifiers/cache-test.ts index 9998a66711d..581c8bcb797 100644 --- a/tests/main/tests/integration/identifiers/cache-test.ts +++ b/tests/main/tests/integration/identifiers/cache-test.ts @@ -107,9 +107,9 @@ module('Integration | Identifiers - cache', function (hooks) { }; const store = this.owner.lookup('service:store') as Store; const cache = store.identifierCache; - let identifier = cache.createIdentifierForNewRecord(runspiredHash); + const identifier = cache.createIdentifierForNewRecord(runspiredHash); - let mergedIdentifier = cache.updateRecordIdentifier(identifier, { type: 'person', id: '1' }); + const mergedIdentifier = cache.updateRecordIdentifier(identifier, { type: 'person', id: '1' }); assert.strictEqual(mergedIdentifier.id, identifier.id, 'merged identifier has same id'); assert.strictEqual(mergedIdentifier.type, identifier.type, 'merged identifier has same type'); @@ -125,9 +125,9 @@ module('Integration | Identifiers - cache', function (hooks) { }; const store = this.owner.lookup('service:store') as Store; const cache = store.identifierCache; - let identifier = cache.createIdentifierForNewRecord(runspiredHash); + const identifier = cache.createIdentifierForNewRecord(runspiredHash); - let mergedIdentifier = cache.updateRecordIdentifier(identifier, { type: 'person', id: '2' }); + const mergedIdentifier = cache.updateRecordIdentifier(identifier, { type: 'person', id: '2' }); assert.strictEqual(mergedIdentifier.id, '2', 'merged identifier has new id'); assert.strictEqual(mergedIdentifier.type, 'person', 'merged identifier has same type'); @@ -159,9 +159,9 @@ module('Integration | Identifiers - cache', function (hooks) { }; const store = this.owner.lookup('service:store') as Store; const cache = store.identifierCache; - let identifier = cache.createIdentifierForNewRecord(runspiredHash); + const identifier = cache.createIdentifierForNewRecord(runspiredHash); - let mergedIdentifier = cache.updateRecordIdentifier(identifier, { type: 'person', id: null }); + const mergedIdentifier = cache.updateRecordIdentifier(identifier, { type: 'person', id: null }); assert.strictEqual(mergedIdentifier.id, null, 'merged identifier has null id'); assert.strictEqual(mergedIdentifier.type, identifier.type, 'merged identifier has same type'); diff --git a/tests/main/tests/integration/identifiers/configuration-test.ts b/tests/main/tests/integration/identifiers/configuration-test.ts index 44e39961068..eee2274176f 100644 --- a/tests/main/tests/integration/identifiers/configuration-test.ts +++ b/tests/main/tests/integration/identifiers/configuration-test.ts @@ -1,7 +1,6 @@ import EmberObject, { set } from '@ember/object'; import { settled } from '@ember/test-helpers'; -import type { IdentifierBucket, StableIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import { module, test } from 'qunit'; import Store from 'ember-data/store'; @@ -19,6 +18,7 @@ import { setIdentifierUpdateMethod, } from '@ember-data/store'; import type { GenerationMethod, ResourceData } from '@ember-data/store/-types/q/identifier'; +import type { IdentifierBucket, StableIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; module('Integration | Identifiers - configuration', function (hooks) { setupTest(hooks); @@ -72,7 +72,7 @@ module('Integration | Identifiers - configuration', function (hooks) { setIdentifierForgetMethod(null); }); - test(`The configured generation method is used for pushed records`, async function (assert) { + test(`The configured generation method is used for pushed records`, function (assert) { const store = this.owner.lookup('service:store') as unknown as Store; const record = store.push({ data: { @@ -89,7 +89,7 @@ module('Integration | Identifiers - configuration', function (hooks) { assert.strictEqual(identifier.lid, 'remote:user:1', 'We receive the expected identifier for an existing record'); }); - test(`The configured generation method is used for newly created records`, async function (assert) { + test(`The configured generation method is used for newly created records`, function (assert) { let localIdInc = 9000; const generationMethod: GenerationMethod = (resource: unknown, bucket: IdentifierBucket) => { if (bucket !== 'record') { @@ -153,6 +153,7 @@ module('Integration | Identifiers - configuration', function (hooks) { this.owner.register('serializer:application', TestSerializer); let updateMethodCalls = 0 as number; + // eslint-disable-next-line @typescript-eslint/no-explicit-any, prefer-const let updateCallback: (...args: any[]) => void; function updateMethod( @@ -217,6 +218,7 @@ module('Integration | Identifiers - configuration', function (hooks) { this.owner.register('serializer:application', TestSerializer); let updateMethodCalls = 0 as number; + // eslint-disable-next-line prefer-const, @typescript-eslint/no-explicit-any let updateCallback: (...args: any[]) => void; function updateMethod( @@ -286,6 +288,7 @@ module('Integration | Identifiers - configuration', function (hooks) { this.owner.register('serializer:application', TestSerializer); let updateMethodCalls = 0 as number; + // eslint-disable-next-line prefer-const, @typescript-eslint/no-explicit-any let updateCallback: (...args: any[]) => void; function updateMethod( @@ -386,9 +389,11 @@ module('Integration | Identifiers - configuration', function (hooks) { throw new Error(`Unexpected generation of new resource identifier`); } generateLidCalls++; + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions return `${resource.type}:${resource.id}`; }); let forgetMethodCalls = 0; + // eslint-disable-next-line prefer-const let expectedIdentifier; let testMethod = (identifier) => { @@ -454,6 +459,7 @@ module('Integration | Identifiers - configuration', function (hooks) { test(`The forget method is called when a record deletion is fully persisted and the record unloaded`, async function (assert) { let forgetMethodCalls = 0; + // eslint-disable-next-line prefer-const let expectedIdentifier; setIdentifierForgetMethod((identifier) => { @@ -528,7 +534,7 @@ module('Integration | Identifiers - configuration', function (hooks) { setIdentifierForgetMethod((identifier) => { forgetMethodCalls++; - let expectedIdentifier = expectedIdentifiers.shift(); + const expectedIdentifier = expectedIdentifiers.shift(); if (expectedIdentifier) { assert.strictEqual( expectedIdentifier, diff --git a/tests/main/tests/integration/identifiers/new-records-test.ts b/tests/main/tests/integration/identifiers/new-records-test.ts index 15dad45af39..8da8928dbe0 100644 --- a/tests/main/tests/integration/identifiers/new-records-test.ts +++ b/tests/main/tests/integration/identifiers/new-records-test.ts @@ -20,7 +20,7 @@ module('Integration | Identifiers - creating new records', function (hooks) { store = owner.lookup('service:store'); }); - test(`We can peek before create`, async function (assert) { + test(`We can peek before create`, function (assert) { let record = store.peekRecord('user', '1'); assert.strictEqual(record, null, 'peekRecord returns null'); diff --git a/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts b/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts index 11798f21c79..c86f7aa7378 100644 --- a/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts +++ b/tests/main/tests/integration/identifiers/polymorphic-scenarios-test.ts @@ -6,10 +6,30 @@ import { setupTest } from 'ember-qunit'; import Adapter from '@ember-data/adapter'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; +import type Store from '@ember-data/store'; import { recordIdentifierFor } from '@ember-data/store'; type RID = { type: string; id: string }; +class Car extends Model { + @attr() + declare color: string; +} + +class Ferrari extends Car {} +class Bmw extends Car {} + +class Dealership extends Model { + @attr() + declare name: string; + + @belongsTo('car', { polymorphic: true, async: true, inverse: null }) + declare bestCar; + + @hasMany('car', { polymorphic: true, async: true, inverse: null }) + declare allCars; +} + module('Integration | Identifiers - single-table-inheritance polymorphic scenarios', function (hooks) { /* In single-table polymorphism, each polymorphic type shares a common primaryKey field. @@ -27,10 +47,10 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari setupTest(hooks); module('single-table', function (innerHooks) { - let store; + let store: Store; class TestSerializer extends EmberObject { - normalizeResponse(_, __, payload) { + normalizeResponse(_, __, payload: unknown) { return payload; } } @@ -38,30 +58,13 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari innerHooks.beforeEach(function () { const { owner } = this; - class Car extends Model { - @attr() - declare color: string; - } - - class Ferrari extends Car {} - class Bmw extends Car {} - - class Dealership extends Model { - @attr() - declare name: string; - @belongsTo('car', { polymorphic: true, async: true, inverse: null }) - declare bestCar; - @hasMany('car', { polymorphic: true, async: true, inverse: null }) - declare allCars; - } - owner.register('serializer:application', TestSerializer); owner.register('model:car', Car); owner.register('model:ferrari', Ferrari); owner.register('model:bmw', Bmw); owner.register('model:dealership', Dealership); - store = owner.lookup('service:store'); + store = owner.lookup('service:store') as Store; }); test(`Identity of polymorphic relations can change type on first load`, async function (assert) { @@ -70,7 +73,7 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari override shouldBackgroundReloadRecord() { return false; } - override findRecord(_, __, id) { + override findRecord(_, __, id: string) { return Promise.resolve({ data: { id, @@ -84,11 +87,11 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari } owner.register('adapter:application', TestAdapter); - const foundFerrari = await store.findRecord('car', '1'); + const foundFerrari = (await store.findRecord('car', '1')) as Car; assert.strictEqual(foundFerrari.constructor.modelName, 'ferrari', 'We found the right type'); assert.strictEqual(recordIdentifierFor(foundFerrari).type, 'ferrari', 'We ended with the correct type'); - const cachedFerrari = await store.peekRecord('ferrari', '1'); + const cachedFerrari = (await store.peekRecord('ferrari', '1')) as Ferrari; assert.strictEqual(cachedFerrari.constructor.modelName, 'ferrari', 'We cached the right type'); assert.strictEqual(recordIdentifierFor(cachedFerrari).type, 'ferrari', 'We ended with the correct type'); assert.strictEqual(foundFerrari, cachedFerrari, 'We have the same car'); @@ -107,7 +110,7 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari override shouldBackgroundReloadRecord() { return false; } - override findRecord(_, { modelName: type }, id) { + override findRecord(_, { modelName: type }, id: string) { if (type === 'dealership') { return Promise.resolve({ data: { @@ -145,13 +148,13 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari } } owner.register('adapter:application', TestAdapter); - const topRecord = await store.findRecord('dealership', '1'); + const topRecord = (await store.findRecord('dealership', '1')) as Dealership; const relation = await topRecord.bestCar; assert.strictEqual(relation.id, '1', 'We found the right id'); assert.strictEqual(relation.constructor.modelName, 'ferrari', 'We found the right type'); - const foundFerrari = await store.findRecord('car', '1'); + const foundFerrari = (await store.findRecord('car', '1')) as Car; assert.strictEqual(relation, foundFerrari, 'We found the ferrari by finding car 1'); const allCars = await topRecord.allCars; @@ -166,7 +169,7 @@ module('Integration | Identifiers - single-table-inheritance polymorphic scenari 'We fetched all the right cars' ); const bmw = allCars.at(1); - const foundBmw = await store.findRecord('car', '2'); + const foundBmw = (await store.findRecord('car', '2')) as Car; assert.strictEqual(foundBmw, bmw, 'We found the bmw by finding car 2'); assert.deepEqual(requests, expectedRequests, 'We triggered the expected requests'); diff --git a/tests/main/tests/integration/identifiers/record-identifier-for-test.ts b/tests/main/tests/integration/identifiers/record-identifier-for-test.ts index ea191c6c8f6..8dafcecb4d0 100644 --- a/tests/main/tests/integration/identifiers/record-identifier-for-test.ts +++ b/tests/main/tests/integration/identifiers/record-identifier-for-test.ts @@ -6,25 +6,27 @@ import { setupTest } from 'ember-qunit'; import Adapter from '@ember-data/adapter'; import Model, { attr } from '@ember-data/model'; +import type Store from '@ember-data/store'; import { recordIdentifierFor } from '@ember-data/store'; +class User extends Model { + + @attr() name; +} + module('Integration | Identifiers - recordIdentifierFor', function (hooks) { setupTest(hooks); - let store; + let store: Store; hooks.beforeEach(function () { const { owner } = this; - class User extends Model { - @attr() name; - } - owner.register('model:user', User); - store = owner.lookup('service:store'); + store = owner.lookup('service:store') as Store; }); - test(`It works for newly created records`, async function (assert) { - const record = store.createRecord('user', { name: 'Chris' }); + test(`It works for newly created records`, function (assert) { + const record = store.createRecord('user', { name: 'Chris' }) as User; assert.strictEqual(record.name, 'Chris', 'We created a record'); const identifier = recordIdentifierFor(record); @@ -48,13 +50,13 @@ module('Integration | Identifiers - recordIdentifierFor', function (hooks) { } } class TestSerializer extends EmberObject { - normalizeResponse(_, __, payload) { + normalizeResponse(_, __, payload: unknown) { return payload; } } this.owner.register('adapter:application', TestAdapter); this.owner.register('serializer:application', TestSerializer); - const record = store.createRecord('user', { name: 'Chris' }); + const record = store.createRecord('user', { name: 'Chris' }) as User; assert.strictEqual(record.name, 'Chris', 'We created a record'); const identifier = recordIdentifierFor(record); @@ -71,7 +73,7 @@ module('Integration | Identifiers - recordIdentifierFor', function (hooks) { assert.ok(typeof identifier.lid === 'string' && identifier.lid.length > 0, 'We have an identifier with an lid'); }); - test(`It works for existing records`, async function (assert) { + test(`It works for existing records`, function (assert) { const record = store.push({ data: { type: 'user', @@ -80,7 +82,7 @@ module('Integration | Identifiers - recordIdentifierFor', function (hooks) { name: 'Chris', }, }, - }); + }) as User; assert.strictEqual(record.name, 'Chris', 'We created a record'); const identifier = recordIdentifierFor(record); diff --git a/tests/main/tests/integration/identifiers/scenarios-test.ts b/tests/main/tests/integration/identifiers/scenarios-test.ts index 4b08052f21d..6a736aa9f96 100644 --- a/tests/main/tests/integration/identifiers/scenarios-test.ts +++ b/tests/main/tests/integration/identifiers/scenarios-test.ts @@ -1,6 +1,6 @@ + import EmberObject, { set } from '@ember/object'; -import type { IdentifierBucket, StableIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import { module, test } from 'qunit'; import type Store from 'ember-data/store'; @@ -16,8 +16,14 @@ import { setIdentifierUpdateMethod, } from '@ember-data/store'; import type { GenerationMethod, ResourceData } from '@ember-data/store/-types/q/identifier'; - -function isNonEmptyString(str: any): str is string { +import type { + Identifier, + IdentifierBucket, + StableIdentifier, + StableRecordIdentifier, +} from '@warp-drive/core-types/identifier'; + +function isNonEmptyString(str: unknown): str is string { return typeof str === 'string' && str.length > 0; } @@ -29,14 +35,17 @@ module('Integration | Identifiers - scenarios', function (hooks) { setupTest(hooks); module('Secondary Cache based on an attribute', function (innerHooks) { - let calls; + const calls = { + findRecord: 0, + queryRecord: 0, + }; let isQuery = false; let secondaryCache: { id: { [key: string]: string }; username: { [key: string]: string }; }; class TestSerializer extends EmberObject { - normalizeResponse(_, __, payload) { + normalizeResponse(_, __, payload: unknown) { return payload; } } @@ -84,15 +93,10 @@ module('Integration | Identifiers - scenarios', function (hooks) { owner.register('serializer:application', TestSerializer); owner.register('model:user', User); - calls = { - findRecord: 0, - queryRecord: 0, - }; - let localIdInc = 9000; secondaryCache = { - id: Object.create(null), - username: Object.create(null), + id: Object.create(null) as Record, + username: Object.create(null) as Record, }; const generationMethod: GenerationMethod = (resource: unknown, bucket: IdentifierBucket) => { if (bucket !== 'record') { @@ -111,7 +115,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { } let lid = resource.lid; - let username = 'attributes' in resource && resource.attributes && resource.attributes.username; + const username = 'attributes' in resource && resource.attributes && resource.attributes.username; // try the username cache if (!lid && isNonEmptyString(username)) { @@ -172,7 +176,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { const recordById = await store.findRecord('user', '1'); const identifierById = recordIdentifierFor(recordById); const recordByUsername = await store.queryRecord('user', { username: '@runspired' }); - const identifierByUsername = recordIdentifierFor(recordByUsername!); + const identifierByUsername = recordIdentifierFor(recordByUsername); assert.strictEqual(identifierById, identifierByUsername, 'The identifiers should be identical'); assert.strictEqual(recordById, recordByUsername, 'The records should be identical'); @@ -191,7 +195,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { test(`queryRecord with username then findRecord with id`, async function (assert) { const store = this.owner.lookup('service:store') as unknown as Store; const recordByUsername = await store.queryRecord('user', { username: '@runspired' }); - const identifierByUsername = recordIdentifierFor(recordByUsername!); + const identifierByUsername = recordIdentifierFor(recordByUsername); const recordById = await store.findRecord('user', '1'); const identifierById = recordIdentifierFor(recordById); @@ -220,8 +224,8 @@ module('Integration | Identifiers - scenarios', function (hooks) { const recordByUsername2 = await recordByUsernamePromise2; const identifierById = recordIdentifierFor(recordById); - const identifierByUsername1 = recordIdentifierFor(recordByUsername1!); - const identifierByUsername2 = recordIdentifierFor(recordByUsername2!); + const identifierByUsername1 = recordIdentifierFor(recordByUsername1); + const identifierByUsername2 = recordIdentifierFor(recordByUsername2); assert.strictEqual(identifierById, identifierByUsername1, 'The identifiers should be identical'); assert.strictEqual(identifierById, identifierByUsername2, 'The identifiers should be identical'); @@ -242,11 +246,14 @@ module('Integration | Identifiers - scenarios', function (hooks) { }); module('Secondary Cache using an attribute as an alternate id', function (innerHooks) { - let calls; + const calls = { + findRecord: 0, + queryRecord: 0, + }; let isQuery = false; let secondaryCache: { [key: string]: string }; class TestSerializer extends EmberObject { - normalizeResponse(_, __, payload) { + normalizeResponse(_, __, payload: unknown) { return payload; } } @@ -294,13 +301,8 @@ module('Integration | Identifiers - scenarios', function (hooks) { owner.register('serializer:application', TestSerializer); owner.register('model:user', User); - calls = { - findRecord: 0, - queryRecord: 0, - }; - let localIdInc = 9000; - secondaryCache = Object.create(null); + secondaryCache = Object.create(null) as Record; function lidForUser(resource: ResourceData | { type: string }): string { if ('type' in resource && resource.type === 'user') { @@ -308,7 +310,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { return `local:user:${localIdInc++}`; } let lid = resource.lid; - let username = 'attributes' in resource && resource.attributes && resource.attributes.username; + const username = 'attributes' in resource && resource.attributes && resource.attributes.username; // try the username cache if (!lid && isNonEmptyString(username)) { @@ -385,6 +387,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { (resource as ResourceData).lid = identifier.lid; lidForUser(resource as ResourceData); } else { + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions throw new Error(`Unhandled update for ${bucket}`); } }; @@ -658,7 +661,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { }); }; - function updateUsernameCache(identifier, oldUsername, newUsername) { + function updateUsernameCache(identifier: Identifier, oldUsername: string, newUsername: string) { if (secondaryCache[oldUsername] !== identifier.lid) { throw new Error(`Incorrect username update`); } @@ -667,7 +670,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { } secondaryCache[newUsername] = identifier.lid; } - function commitUsernameUpdate(identifier, oldUsername, newUsername) { + function commitUsernameUpdate(identifier: Identifier, oldUsername: string, newUsername: string) { if (secondaryCache[oldUsername] === identifier.lid) { delete secondaryCache[oldUsername]; } diff --git a/tests/main/tests/integration/model-errors-test.ts b/tests/main/tests/integration/model-errors-test.ts index 336a24f9028..eb2f1c2032b 100644 --- a/tests/main/tests/integration/model-errors-test.ts +++ b/tests/main/tests/integration/model-errors-test.ts @@ -1,7 +1,9 @@ + import 'qunit-dom'; // tell TS consider *.dom extension for assert import { setComponentTemplate } from '@ember/component'; import { get } from '@ember/object'; +import type Owner from '@ember/owner'; import { render, settled } from '@ember/test-helpers'; import Component from '@glimmer/component'; @@ -11,6 +13,7 @@ import { hbs } from 'ember-cli-htmlbars'; import { setupRenderingTest } from 'ember-qunit'; import Model, { attr } from '@ember-data/model'; +import type Store from '@ember-data/store'; class Tag extends Model { @attr('string', {}) @@ -34,14 +37,14 @@ const template = hbs` interface CurrentTestContext { tag: Tag; - owner: any; + owner: Owner; } module('integration/model.errors', function (hooks) { setupRenderingTest(hooks); hooks.beforeEach(function (this: CurrentTestContext) { - let { owner } = this; + const { owner } = this; owner.register('model:tag', Tag); // @ts-expect-error @@ -49,7 +52,8 @@ module('integration/model.errors', function (hooks) { }); test('Model errors are autotracked', async function (this: CurrentTestContext, assert) { - this.tag = this.owner.lookup('service:store').createRecord('tag'); + this.tag = (this.owner.lookup('service:store') as Store).createRecord('tag', {}) as Tag; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const errors: any = get(this.tag, 'errors'); await render(hbs``); diff --git a/tests/main/tests/integration/peek-all-test.js b/tests/main/tests/integration/peek-all-test.js index b991f2f067c..2737dbac42c 100644 --- a/tests/main/tests/integration/peek-all-test.js +++ b/tests/main/tests/integration/peek-all-test.js @@ -18,7 +18,7 @@ module('integration/peek-all - DS.Store#peekAll()', function (hooks) { let store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); store = owner.lookup('service:store'); @@ -44,7 +44,7 @@ module('integration/peek-all - DS.Store#peekAll()', function (hooks) { ], }); - let all = store.peekAll('person'); + const all = store.peekAll('person'); assert.strictEqual(get(all, 'length'), 2); store.push({ diff --git a/tests/main/tests/integration/polymorphic-belongs-to-test.js b/tests/main/tests/integration/polymorphic-belongs-to-test.js index 30321d89a1b..645490f4462 100644 --- a/tests/main/tests/integration/polymorphic-belongs-to-test.js +++ b/tests/main/tests/integration/polymorphic-belongs-to-test.js @@ -9,7 +9,7 @@ module('integration/polymorphic-belongs-to - Polymorphic BelongsTo', function (h let store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; class Book extends Model { @attr() title; @@ -38,7 +38,7 @@ module('integration/polymorphic-belongs-to - Polymorphic BelongsTo', function (h }); test('using store.push with a null value for a payload in relationships sets the Models relationship to null - sync relationship', function (assert) { - let payload = { + const payload = { data: { type: 'book', id: '1', @@ -62,10 +62,10 @@ module('integration/polymorphic-belongs-to - Polymorphic BelongsTo', function (h }; store.push(payload); - let book = store.peekRecord('book', 1); + const book = store.peekRecord('book', 1); assert.strictEqual(book.author.id, '1'); - let payloadThatResetsBelongToRelationship = { + const payloadThatResetsBelongToRelationship = { data: { type: 'book', id: '1', @@ -83,7 +83,7 @@ module('integration/polymorphic-belongs-to - Polymorphic BelongsTo', function (h }); test('using store.push with a null value for a payload in relationships sets the Models relationship to null - async relationship', function (assert) { - let payload = { + const payload = { data: { type: 'async-book', id: '1', @@ -107,9 +107,9 @@ module('integration/polymorphic-belongs-to - Polymorphic BelongsTo', function (h }; store.push(payload); - let book = store.peekRecord('async-book', 1); + const book = store.peekRecord('async-book', 1); - let payloadThatResetsBelongToRelationship = { + const payloadThatResetsBelongToRelationship = { data: { type: 'async-book', id: '1', diff --git a/tests/main/tests/integration/record-array-manager-test.js b/tests/main/tests/integration/record-array-manager-test.js index 1d13fb62840..bbda95bfb64 100644 --- a/tests/main/tests/integration/record-array-manager-test.js +++ b/tests/main/tests/integration/record-array-manager-test.js @@ -33,7 +33,7 @@ class Car extends Model { module('integration/record_array_manager', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('adapter:application', RESTAdapter); owner.register('model:car', Car); owner.register('model:person', Person); @@ -59,7 +59,7 @@ module('integration/record_array_manager', function (hooks) { }, }); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -74,10 +74,10 @@ module('integration/record_array_manager', function (hooks) { }, }); - let all = store.peekAll('person'); - let query = {}; - let adapterPopulated = manager.createArray({ type: 'person', query }); - let identifier = recordIdentifierFor(person); + const all = store.peekAll('person'); + const query = {}; + const adapterPopulated = manager.createArray({ type: 'person', query }); + const identifier = recordIdentifierFor(person); assert.false(all.isDestroyed, 'initial: LiveArray is not destroyed'); assert.false(adapterPopulated.isDestroyed, 'initial: Collection is not destroyed'); @@ -115,7 +115,7 @@ module('integration/record_array_manager', function (hooks) { const query = {}; - let adapterPopulated = manager.createArray({ type: 'car', query }); + const adapterPopulated = manager.createArray({ type: 'car', query }); adapterPopulated.destroy(); await settled(); @@ -124,7 +124,7 @@ module('integration/record_array_manager', function (hooks) { }); test('liveArrayFor (base)', function (assert) { - let recordArray = manager.liveArrayFor('foo'); + const recordArray = manager.liveArrayFor('foo'); assert.strictEqual(recordArray.modelName, 'foo'); assert.true(recordArray.isLoaded); diff --git a/tests/main/tests/integration/record-array-test.js b/tests/main/tests/integration/record-array-test.js index b520055f657..136c650beac 100644 --- a/tests/main/tests/integration/record-array-test.js +++ b/tests/main/tests/integration/record-array-test.js @@ -31,14 +31,14 @@ module('integration/record-array - RecordArray', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); }); test('acts as a live query', async function (assert) { const store = this.owner.lookup('service:store'); - let recordArray = store.peekAll('person'); + const recordArray = store.peekAll('person'); store.push({ data: { @@ -79,8 +79,8 @@ module('integration/record-array - RecordArray', function (hooks) { async function (assert) { const store = this.owner.lookup('service:store'); - let recordArray = store.peekAll('Person'); - let otherRecordArray = store.peekAll('person'); + const recordArray = store.peekAll('Person'); + const otherRecordArray = store.peekAll('person'); assert.strictEqual(recordArray, otherRecordArray, 'Person and person are the same record-array'); @@ -165,9 +165,9 @@ module('integration/record-array - RecordArray', function (hooks) { ], }); - let scumbag = await store.findRecord('person', '1'); - let tag = await store.findRecord('tag', '1'); - let recordArray = tag.people; + const scumbag = await store.findRecord('person', '1'); + const tag = await store.findRecord('tag', '1'); + const recordArray = tag.people; recordArray.push(scumbag); @@ -331,8 +331,8 @@ module('integration/record-array - RecordArray', function (hooks) { ], }); - let scumbag = store.peekRecord('person', 1); - let tag = store.peekRecord('tag', 1); + const scumbag = store.peekRecord('person', 1); + const tag = store.peekRecord('tag', 1); scumbag.deleteRecord(); @@ -383,9 +383,9 @@ module('integration/record-array - RecordArray', function (hooks) { ], }); - let scumbag = store.peekRecord('person', 1); - let tag = store.peekRecord('tag', 1); - let tool = store.peekRecord('tool', 1); + const scumbag = store.peekRecord('person', 1); + const tag = store.peekRecord('tag', 1); + const tool = store.peekRecord('tool', 1); assert.strictEqual(tag.people.length, 1, 'record is in the record array'); assert.strictEqual(tool.person, scumbag, 'the tool belongs to the record'); @@ -400,8 +400,8 @@ module('integration/record-array - RecordArray', function (hooks) { test('a newly created record is removed from a record array when it is deleted', async function (assert) { const store = this.owner.lookup('service:store'); - let recordArray = store.peekAll('person'); - let scumbag = store.createRecord('person', { + const recordArray = store.peekAll('person'); + const scumbag = store.createRecord('person', { name: 'Scumbag Dale', }); @@ -451,7 +451,7 @@ module('integration/record-array - RecordArray', function (hooks) { ], }); - let recordArray = store.peekAll('person'); + const recordArray = store.peekAll('person'); assert.strictEqual(recordArray.at(20), undefined, 'objects outside of the range just return undefined'); }); @@ -486,7 +486,7 @@ module('integration/record-array - RecordArray', function (hooks) { ], }); - let recordArray = store.peekAll('person'); + const recordArray = store.peekAll('person'); assert.strictEqual(recordArray.at(2).id, '3', 'should retrieve correct record at index 2'); assert.strictEqual(recordArray.at(1).id, '2', 'should retrieve correct record at index 1'); @@ -497,7 +497,7 @@ module('integration/record-array - RecordArray', function (hooks) { const store = this.owner.lookup('service:store'); assert.expect(2); - let adapter = store.adapterFor('person'); + const adapter = store.adapterFor('person'); adapter.query = function (store, type, query, recordArray) { assert.false(recordArray.isLoaded, 'not loaded yet'); @@ -510,7 +510,7 @@ module('integration/record-array - RecordArray', function (hooks) { }); }; - let people = await store.query('person', { page: 1 }); + const people = await store.query('person', { page: 1 }); assert.true(people.isLoaded, 'The array is now loaded'); }); diff --git a/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js b/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js index 9c999b67758..1d41bea6a94 100644 --- a/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js +++ b/tests/main/tests/integration/record-arrays/adapter-populated-record-array-test.js @@ -34,10 +34,10 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula this.owner.register('adapter:application', ApplicationAdapter); - let store = this.owner.lookup('service:store'); - let recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); + const store = this.owner.lookup('service:store'); + const recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); - let payload = { + const payload = { data: [ { type: 'person', @@ -63,7 +63,7 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula ], }; - let results = store._push(payload); + const results = store._push(payload); store.recordArrayManager.populateManagedArray(recordArray, results, payload); @@ -75,10 +75,10 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula }); test('stores the metadata off the payload', async function (assert) { - let store = this.owner.lookup('service:store'); - let recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); + const store = this.owner.lookup('service:store'); + const recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); - let payload = { + const payload = { data: [ { type: 'person', @@ -107,17 +107,17 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula }, }; - let results = store._push(payload); + const results = store._push(payload); store.recordArrayManager.populateManagedArray(recordArray, results, payload); assert.strictEqual(recordArray.meta.foo, 'bar', 'expected meta.foo to be bar from payload'); }); test('stores the links off the payload', async function (assert) { - let store = this.owner.lookup('service:store'); - let recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); + const store = this.owner.lookup('service:store'); + const recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); - let payload = { + const payload = { data: [ { type: 'person', @@ -146,15 +146,15 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula }, }; - let results = store._push(payload); + const results = store._push(payload); store.recordArrayManager.populateManagedArray(recordArray, results, payload); assert.strictEqual(recordArray.links.first, '/foo?page=1', 'expected links.first to be "/foo?page=1" from payload'); }); test('recordArray.splice() throws error', async function (assert) { - let store = this.owner.lookup('service:store'); - let recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); + const store = this.owner.lookup('service:store'); + const recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); await settled(); @@ -168,8 +168,8 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula }); test('recordArray mutation throws error', async function (assert) { - let store = this.owner.lookup('service:store'); - let recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); + const store = this.owner.lookup('service:store'); + const recordArray = store.recordArrayManager.createArray({ type: 'person', query: null }); await settled(); @@ -184,16 +184,16 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula test('pass record array to adapter.query regardless of its arity', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let payload = { + const payload = { data: [ { id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }, { id: '2', type: 'person', attributes: { name: 'Scumbag Katz' } }, ], }; - let actualQuery = {}; + const actualQuery = {}; // arity 3 adapter.query = function (store, type, query) { @@ -214,8 +214,8 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula }); test('loadRecord re-syncs identifiers recordArrays', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let payload = { data: [ @@ -256,10 +256,9 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula test('when an adapter populated record gets updated the array contents are also updated', async function (assert) { assert.expect(8); - let queryArr, findArray; - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let array = [{ id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }]; + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const array = [{ id: '1', type: 'person', attributes: { name: 'Scumbag Dale' } }]; // resemble server side filtering adapter.query = function (store, type, query, recordArray) { @@ -272,8 +271,8 @@ module('integration/record-arrays/adapter_populated_record_array - AdapterPopula return { data: array.slice(0) }; }; - queryArr = await store.query('person', { slice: 1 }); - findArray = await store.findAll('person'); + const queryArr = await store.query('person', { slice: 1 }); + const findArray = await store.findAll('person'); assert.strictEqual(queryArr.length, 0, 'No records for this query'); assert.false(queryArr.isUpdating, 'Record array isUpdating state updated'); diff --git a/tests/main/tests/integration/record-arrays/peeked-records-test.js b/tests/main/tests/integration/record-arrays/peeked-records-test.js index 731d338828d..a9bf46b6ff1 100644 --- a/tests/main/tests/integration/record-arrays/peeked-records-test.js +++ b/tests/main/tests/integration/record-arrays/peeked-records-test.js @@ -27,8 +27,8 @@ module('integration/peeked-records', function (hooks) { }); test('repeated calls to peekAll in separate run-loops works as expected', async function (assert) { - let peekedRecordArray = store.peekAll('person'); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = store.peekAll('person'); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state initial access'); @@ -69,8 +69,8 @@ module('integration/peeked-records', function (hooks) { }); test('peekAll in the same run-loop as push works as expected', async function (assert) { - let peekedRecordArray = store.peekAll('person'); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = store.peekAll('person'); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state initial'); @@ -112,13 +112,13 @@ module('integration/peeked-records', function (hooks) { }); test('newly created records notify the array as expected', async function (assert) { - let peekedRecordArray = store.peekAll('person'); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = store.peekAll('person'); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state initial'); - let aNewlyCreatedRecord = store.createRecord('person', { + const aNewlyCreatedRecord = store.createRecord('person', { name: 'James', }); await settled(); @@ -132,13 +132,13 @@ module('integration/peeked-records', function (hooks) { }); test('immediately peeking newly created records works as expected', async function (assert) { - let peekedRecordArray = store.peekAll('person'); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = store.peekAll('person'); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.strictEqual(peekedRecordArray.length, 0); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state initial'); - let aNewlyCreatedRecord = store.createRecord('person', { + const aNewlyCreatedRecord = store.createRecord('person', { name: 'James', }); @@ -159,11 +159,11 @@ module('integration/peeked-records', function (hooks) { }); test('unloading newly created records notify the array as expected', async function (assert) { - let peekedRecordArray = store.peekAll('person'); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = store.peekAll('person'); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state init'); - let aNewlyCreatedRecord = store.createRecord('person', { + const aNewlyCreatedRecord = store.createRecord('person', { name: 'James', }); @@ -179,12 +179,12 @@ module('integration/peeked-records', function (hooks) { }); test('immediately peeking after unloading newly created records works as expected', async function (assert) { - let peekedRecordArray = store.peekAll('person'); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = store.peekAll('person'); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state init'); - let aNewlyCreatedRecord = store.createRecord('person', { + const aNewlyCreatedRecord = store.createRecord('person', { name: 'James', }); @@ -200,9 +200,9 @@ module('integration/peeked-records', function (hooks) { }); test('unloadAll followed by peekAll in the same run-loop works as expected', async function (assert) { - let peekedRecordArray = store.peekAll('person'); + const peekedRecordArray = store.peekAll('person'); assert.strictEqual(peekedRecordArray.length, 0, 'length is 0'); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state init'); @@ -289,8 +289,8 @@ module('integration/peeked-records', function (hooks) { return result; } - let peekedRecordArray = await peek(); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = await peek(); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state init'); @@ -342,8 +342,8 @@ module('integration/peeked-records', function (hooks) { return result; } - let peekedRecordArray = await peek(); - let watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); + const peekedRecordArray = await peek(); + const watcher = watchProperties.call(this, peekedRecordArray, ['length', '[]']); await startWatching.call(this); assert.watchedPropertyCounts(watcher, { length: 1, '[]': 1 }, 'RecordArray state init'); diff --git a/tests/main/tests/integration/record-data/record-data-errors-test.ts b/tests/main/tests/integration/record-data/record-data-errors-test.ts index 389908f9770..2216c3211dd 100644 --- a/tests/main/tests/integration/record-data/record-data-errors-test.ts +++ b/tests/main/tests/integration/record-data/record-data-errors-test.ts @@ -1,16 +1,5 @@ import EmberObject from '@ember/object'; -import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph'; -import type { - RecordIdentifier, - StableExistingRecordIdentifier, - StableRecordIdentifier, -} from '@warp-drive/core-types/identifier'; -import type { - CollectionResourceDocument, - JsonApiDocument, - SingleResourceDocument, -} from '@warp-drive/core-types/spec/raw'; import { module, test } from 'qunit'; import Store from 'ember-data/store'; @@ -23,18 +12,29 @@ import { recordIdentifierFor } from '@ember-data/store'; import type { Cache, MergeOperation } from '@ember-data/store/-types/q/cache'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; import type { JsonApiError, JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; -import { ChangedAttributesHash, RelationshipDiff } from '@warp-drive/core-types/cache'; +import type { ChangedAttributesHash, RelationshipDiff } from '@warp-drive/core-types/cache'; import type { ResourceBlob } from '@warp-drive/core-types/cache/aliases'; -import { Change } from '@warp-drive/core-types/cache/change'; -import { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship'; -import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier'; -import { +import type { Change } from '@warp-drive/core-types/cache/change'; +import type { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship'; +import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph'; +import type { + RecordIdentifier, + StableDocumentIdentifier, + StableExistingRecordIdentifier, + StableRecordIdentifier, +} from '@warp-drive/core-types/identifier'; +import type { CollectionResourceDataDocument, ResourceDocument, ResourceErrorDocument, ResourceMetaDocument, SingleResourceDataDocument, } from '@warp-drive/core-types/spec/document'; +import type { + CollectionResourceDocument, + JsonApiDocument, + SingleResourceDocument, +} from '@warp-drive/core-types/spec/raw'; class Person extends Model { @attr declare firstName: string; @@ -105,7 +105,7 @@ class TestRecordData implements Cache { version = '2' as const; _errors?: JsonApiError[]; - _isNew: boolean = false; + _isNew = false; upsert( identifier: StableRecordIdentifier, @@ -340,6 +340,7 @@ module('integration/record-data Custom RecordData (v2) Errors', function (hooks) }) as Model; const identifier = recordIdentifierFor(person); + let nameError = person.errors.errorsFor('firstName').objectAt(0); assert.strictEqual(nameError, undefined, 'no error shows up on firstName initially'); assert.true(person.isValid, 'person is initially valid'); @@ -355,13 +356,16 @@ module('integration/record-data Custom RecordData (v2) Errors', function (hooks) ]; storeWrapper.notifyChange(identifier, 'errors'); + nameError = person.errors.errorsFor('firstName').objectAt(0); + assert.strictEqual(nameError?.attribute, 'firstName', 'error shows up on name'); assert.false(person.isValid, 'person is not valid'); errorsToReturn = []; storeWrapper.notifyChange(identifier, 'errors'); + assert.strictEqual(person.errors.errorsFor('firstName').length, 0, 'no errors on name'); assert.true(person.isValid, 'person is valid'); @@ -377,8 +381,11 @@ module('integration/record-data Custom RecordData (v2) Errors', function (hooks) storeWrapper.notifyChange(identifier, 'errors'); assert.false(person.isValid, 'person is not valid'); + assert.strictEqual(person.errors.errorsFor('firstName').length, 0, 'no errors on firstName'); - let lastNameError = person.errors.errorsFor('lastName').objectAt(0); + + const lastNameError = person.errors.errorsFor('lastName').objectAt(0); + assert.strictEqual(lastNameError?.attribute, 'lastName', 'error shows up on lastName'); }); }); diff --git a/tests/main/tests/integration/record-data/record-data-state-test.ts b/tests/main/tests/integration/record-data/record-data-state-test.ts index 642e05a113a..7814c7c3bf0 100644 --- a/tests/main/tests/integration/record-data/record-data-state-test.ts +++ b/tests/main/tests/integration/record-data/record-data-state-test.ts @@ -1,13 +1,6 @@ import EmberObject from '@ember/object'; import { settled } from '@ember/test-helpers'; -import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph'; -import type { StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; -import type { - CollectionResourceDocument, - JsonApiDocument, - SingleResourceDocument, -} from '@warp-drive/core-types/spec/raw'; import { module, test } from 'qunit'; import Store from 'ember-data/store'; @@ -23,8 +16,13 @@ import type { JsonApiError, JsonApiResource } from '@ember-data/store/-types/q/r import type { ChangedAttributesHash, RelationshipDiff } from '@warp-drive/core-types/cache'; import type { ResourceBlob } from '@warp-drive/core-types/cache/aliases'; import type { Change } from '@warp-drive/core-types/cache/change'; -import { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship'; -import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier'; +import type { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship'; +import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph'; +import type { + StableDocumentIdentifier, + StableExistingRecordIdentifier, + StableRecordIdentifier, +} from '@warp-drive/core-types/identifier'; import type { CollectionResourceDataDocument, ResourceDocument, @@ -32,12 +30,19 @@ import type { ResourceMetaDocument, SingleResourceDataDocument, } from '@warp-drive/core-types/spec/document'; +import type { + CollectionResourceDocument, + JsonApiDocument, + SingleResourceDocument, +} from '@warp-drive/core-types/spec/raw'; class Person extends Model { // TODO fix the typing for naked attrs + @attr('string', {}) name; + @attr('string', {}) lastName; } @@ -136,7 +141,7 @@ class TestRecordData implements Cache { version = '2' as const; _errors?: JsonApiError[]; - _isNew: boolean = false; + _isNew = false; clientDidCreate( identifier: StableRecordIdentifier, @@ -215,7 +220,7 @@ module('integration/record-data - Record Data State', function (hooks) { owner.register('model:person', Person); // @ts-expect-error missing type - // eslint-disable-next-line @typescript-eslint/no-unsafe-call + owner.unregister('service:store'); owner.register('service:store', Store); owner.register('serializer:application', JSONAPISerializer); @@ -236,7 +241,7 @@ module('integration/record-data - Record Data State', function (hooks) { name: 'Scumbag Dale', }, }; - let { owner } = this; + const { owner } = this; class LifecycleRecordData extends TestRecordData { override isNew(): boolean { @@ -263,7 +268,7 @@ module('integration/record-data - Record Data State', function (hooks) { } } - let TestAdapter = EmberObject.extend({ + const TestAdapter = EmberObject.extend({ deleteRecord() { calledDelete = true; return Promise.resolve(); @@ -289,7 +294,7 @@ module('integration/record-data - Record Data State', function (hooks) { data: [personHash], }); - let person = store.peekRecord('person', '1') as Person; + const person = store.peekRecord('person', '1') as Person; isNew = true; await person.save(); assert.true(calledCreate, 'called create if record isNew'); @@ -308,7 +313,9 @@ module('integration/record-data - Record Data State', function (hooks) { test('Record Data state record flags', async function (assert) { assert.expect(13); - let isDeleted: boolean, isNew: boolean, isDeletionCommitted: boolean; + let isDeleted = false; + let isNew = false; + let isDeletionCommitted = false; let calledSetIsDeleted = false; let storeWrapper!: CacheCapabilitiesManager; @@ -319,7 +326,7 @@ module('integration/record-data - Record Data State', function (hooks) { name: 'Scumbag Dale', }, }; - let { owner } = this; + const { owner } = this; class LifecycleRecordData extends TestRecordData { constructor(sw: CacheCapabilitiesManager, identifier: StableRecordIdentifier) { @@ -364,9 +371,9 @@ module('integration/record-data - Record Data State', function (hooks) { data: [personHash], }); - let person = store.peekRecord('person', '1') as Person; - let personIdentifier = recordIdentifierFor(person); - let people = store.peekAll('person'); + const person = store.peekRecord('person', '1') as Person; + const personIdentifier = recordIdentifierFor(person); + const people = store.peekAll('person'); assert.strictEqual(people.length, 1, 'live array starting length is 1'); isNew = true; diff --git a/tests/main/tests/integration/record-data/record-data-test.ts b/tests/main/tests/integration/record-data/record-data-test.ts index 14802c73da2..65e6d783eff 100644 --- a/tests/main/tests/integration/record-data/record-data-test.ts +++ b/tests/main/tests/integration/record-data/record-data-test.ts @@ -1,17 +1,7 @@ + import EmberObject from '@ember/object'; import { settled } from '@ember/test-helpers'; -import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph'; -import type { - RecordIdentifier, - StableExistingRecordIdentifier, - StableRecordIdentifier, -} from '@warp-drive/core-types/identifier'; -import type { - CollectionResourceDocument, - JsonApiDocument, - SingleResourceDocument, -} from '@warp-drive/core-types/spec/raw'; import { module, test } from 'qunit'; import Store from 'ember-data/store'; @@ -27,8 +17,14 @@ import type { JsonApiError, JsonApiResource } from '@ember-data/store/-types/q/r import type { ChangedAttributesHash, RelationshipDiff } from '@warp-drive/core-types/cache'; import type { ResourceBlob } from '@warp-drive/core-types/cache/aliases'; import type { Change } from '@warp-drive/core-types/cache/change'; -import { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship'; -import type { StableDocumentIdentifier } from '@warp-drive/core-types/identifier'; +import type { CollectionRelationship, ResourceRelationship } from '@warp-drive/core-types/cache/relationship'; +import type { LocalRelationshipOperation } from '@warp-drive/core-types/graph'; +import type { + RecordIdentifier, + StableDocumentIdentifier, + StableExistingRecordIdentifier, + StableRecordIdentifier, +} from '@warp-drive/core-types/identifier'; import type { CollectionResourceDataDocument, ResourceDocument, @@ -36,6 +32,11 @@ import type { ResourceMetaDocument, SingleResourceDataDocument, } from '@warp-drive/core-types/spec/document'; +import type { + CollectionResourceDocument, + JsonApiDocument, + SingleResourceDocument, +} from '@warp-drive/core-types/spec/raw'; class Person extends Model { // TODO fix the typing for naked attrs @@ -59,7 +60,7 @@ class TestRecordData implements Cache { version = '2' as const; _errors?: JsonApiError[]; - _isNew: boolean = false; + _isNew = false; _storeWrapper: CacheCapabilitiesManager; _identifier: StableRecordIdentifier; @@ -210,7 +211,7 @@ module('integration/record-data - Custom RecordData Implementations', function ( setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('model:house', House); @@ -244,7 +245,7 @@ module('integration/record-data - Custom RecordData Implementations', function ( ], }); - let all = store.peekAll('person'); + const all = store.peekAll('person'); assert.strictEqual(all.length, 2, 'we have 2 records'); store.push({ @@ -274,7 +275,7 @@ module('integration/record-data - Custom RecordData Implementations', function ( name: 'Scumbag Dale', }, }; - let { owner } = this; + const { owner } = this; let calledUpsert = 0; let calledClientDidCreate = 0; let calledWillCommit = 0; @@ -302,7 +303,7 @@ module('integration/record-data - Custom RecordData Implementations', function ( calledWillCommit++; } - override commitWasRejected(identifier, errors) { + override commitWasRejected(identifier: StableRecordIdentifier, errors: JsonApiError[] | undefined) { super.commitWasRejected(identifier, errors); calledWasRejected++; } @@ -319,7 +320,7 @@ module('integration/record-data - Custom RecordData Implementations', function ( calledRollbackAttributes++; } - override didCommit(identifier, result) { + override didCommit(identifier: StableExistingRecordIdentifier, result: StructuredDataDocument) { calledDidCommit++; isNew = false; return { data: identifier }; @@ -337,7 +338,7 @@ module('integration/record-data - Custom RecordData Implementations', function ( } } - let TestAdapter = EmberObject.extend({ + const TestAdapter = EmberObject.extend({ updateRecord() { called++; if (called === 1) { @@ -362,8 +363,8 @@ module('integration/record-data - Custom RecordData Implementations', function ( }); assert.strictEqual(calledUpsert, 1, 'Called upsert'); - let person = store.peekRecord('person', '1') as Model; - person.save(); + const person = store.peekRecord('person', '1') as Model; + void person.save(); assert.strictEqual(calledWillCommit, 1, 'Called willCommit'); await settled(); @@ -394,10 +395,10 @@ module('integration/record-data - Custom RecordData Implementations', function ( calledRollbackAttributes = 0; calledDidCommit = 0; - let clientPerson = store.createRecord('person', { id: '2' }) as Model; + const clientPerson = store.createRecord('person', { id: '2' }) as Model; assert.strictEqual(calledClientDidCreate, 1, 'Called clientDidCreate'); - clientPerson.save(); + void clientPerson.save(); assert.strictEqual(calledWillCommit, 1, 'Called willCommit'); await settled(); @@ -417,8 +418,8 @@ module('integration/record-data - Custom RecordData Implementations', function ( assert.strictEqual(calledUpsert, 0, 'Did not call pushData'); }); - test('Record Data attribute setting', async function (assert) { - let expectedCount = 13; + test('Record Data attribute setting', function (assert) { + const expectedCount = 13; assert.expect(expectedCount); const personHash = { type: 'person', @@ -428,32 +429,32 @@ module('integration/record-data - Custom RecordData Implementations', function ( }, }; - let { owner } = this; + const { owner } = this; let calledGet = 0; class AttributeRecordData extends TestRecordData { - changedAttributes(): any { - return { name: ['old', 'new'] }; + changedAttributes() { + return { name: ['old', 'new'] as [string, string] }; } hasChangedAttributes(): boolean { return false; } - override changedAttrs(): any { - return { name: ['old', 'new'] }; + override changedAttrs() { + return { name: ['old', 'new'] as [string, string] }; } override hasChangedAttrs(): boolean { return false; } - override setAttr(identifier: StableRecordIdentifier, key: string, value: any) { + override setAttr(identifier: StableRecordIdentifier, key: string, value: unknown) { assert.strictEqual(key, 'name', 'key passed to setDirtyAttribute'); assert.strictEqual(value, 'new value', 'value passed to setDirtyAttribute'); } - setDirtyAttribute(key: string, value: any) { + setDirtyAttribute(key: string, value: unknown) { assert.strictEqual(key, 'name', 'key passed to setDirtyAttribute'); assert.strictEqual(value, 'new value', 'value passed to setDirtyAttribute'); } @@ -481,7 +482,7 @@ module('integration/record-data - Custom RecordData Implementations', function ( data: [personHash], }); - let person = store.peekRecord('person', '1') as Model; + const person = store.peekRecord('person', '1') as Model; assert.strictEqual(person.name, 'new attribute'); assert.strictEqual(calledGet, 1, 'called getAttr for initial get'); person.set('name', 'new value'); diff --git a/tests/main/tests/integration/record-data/store-wrapper-test.ts b/tests/main/tests/integration/record-data/store-wrapper-test.ts index 6f3847d36e9..84b6b210386 100644 --- a/tests/main/tests/integration/record-data/store-wrapper-test.ts +++ b/tests/main/tests/integration/record-data/store-wrapper-test.ts @@ -1,6 +1,6 @@ + import { settled } from '@ember/test-helpers'; -import type { StableRecordIdentifier } from '@warp-drive/core-types'; import { module, test } from 'qunit'; import Store from 'ember-data/store'; @@ -8,8 +8,10 @@ import { setupTest } from 'ember-qunit'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import { recordIdentifierFor } from '@ember-data/store'; -import { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; +import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; import publicProps from '@ember-data/unpublished-test-infra/test-support/public-props'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; +import type { ExistingResourceObject } from '@warp-drive/core-types/spec/raw'; class Person extends Model { @attr('string', {}) @@ -61,13 +63,13 @@ class TestRecordData { unloadRecord() {} rollbackAttributes() {} - changedAttributes(): any {} + changedAttributes(): void {} hasChangedAttributes(): boolean { return false; } - setDirtyAttribute(key: string, value: any) {} + setDirtyAttribute(key: string, value: unknown) {} getAttr(identifier: StableRecordIdentifier, key: string): unknown { return 'test'; @@ -105,13 +107,14 @@ class CustomStore extends Store { } } -let houseHash, houseHash2; +let houseHash: ExistingResourceObject; +let houseHash2: ExistingResourceObject; module('integration/store-wrapper - RecordData StoreWrapper tests', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; houseHash = { type: 'house', id: '1', @@ -136,7 +139,7 @@ module('integration/store-wrapper - RecordData StoreWrapper tests', function (ho owner.register('service:store', CustomStore); }); - test('Relationship definitions', async function (assert) { + test('Relationship definitions', function (assert) { const { owner } = this; let storeWrapper!: CacheCapabilitiesManager; @@ -185,7 +188,7 @@ module('integration/store-wrapper - RecordData StoreWrapper tests', function (ho 'can lookup attribute definitions for other models' ); - let houseRelationships = { + const houseRelationships = { landlord: { key: 'landlord', kind: 'belongsTo', @@ -208,15 +211,15 @@ module('integration/store-wrapper - RecordData StoreWrapper tests', function (ho type: 'person', }, }; - let schema = storeWrapper.getSchemaDefinitionService().relationshipsDefinitionFor({ type: 'house' }); - let result = publicProps(['key', 'kind', 'name', 'type', 'options'], schema); + const schema = storeWrapper.getSchemaDefinitionService().relationshipsDefinitionFor({ type: 'house' }); + const result = publicProps(['key', 'kind', 'name', 'type', 'options'], schema) as Record; - // Retrive only public values from the result + // Retrieve only public values from the result // This should go away once we put private things in symbols/weakmaps assert.deepEqual(houseRelationships, result, 'can lookup relationship definitions'); }); - test('setRecordId', async function (assert) { + test('setRecordId', function (assert) { const { owner } = this; let storeWrapper!: CacheCapabilitiesManager; @@ -230,7 +233,7 @@ module('integration/store-wrapper - RecordData StoreWrapper tests', function (ho owner.register('service:store', TestStore); const store = owner.lookup('service:store') as unknown as Store; - let house = store.createRecord('house', {}) as Model; + const house = store.createRecord('house', {}) as Model; storeWrapper.setRecordId(recordIdentifierFor(house), '17'); assert.strictEqual(house.id, '17', 'setRecordId correctly set the id'); assert.strictEqual( @@ -240,7 +243,7 @@ module('integration/store-wrapper - RecordData StoreWrapper tests', function (ho ); }); - test('hasRecord', async function (assert) { + test('hasRecord', function (assert) { const { owner } = this; let storeWrapper!: CacheCapabilitiesManager; @@ -260,7 +263,7 @@ module('integration/store-wrapper - RecordData StoreWrapper tests', function (ho store.peekRecord('house', '1'); // TODO isRecordInUse returns true if record has never been instantiated, think through whether thats correct - let house2 = store.peekRecord('house', '2') as Model; + const house2 = store.peekRecord('house', '2') as Model; house2.unloadRecord(); store.createRecord('house', {}); diff --git a/tests/main/tests/integration/records/collection-save-test.js b/tests/main/tests/integration/records/collection-save-test.js index c7c95956414..b655405a254 100644 --- a/tests/main/tests/integration/records/collection-save-test.js +++ b/tests/main/tests/integration/records/collection-save-test.js @@ -22,15 +22,15 @@ module('integration/records/collection_save - Save Collection of Records', funct test('Collection will resolve save on success', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let id = 1; store.createRecord('post', { title: 'Hello' }); store.createRecord('post', { title: 'World' }); - let posts = store.peekAll('post'); + const posts = store.peekAll('post'); adapter.createRecord = function (store, type, snapshot) { return Promise.resolve({ data: { id: id++, type: 'post' } }); @@ -42,13 +42,13 @@ module('integration/records/collection_save - Save Collection of Records', funct }); test('Collection will reject save on error', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.createRecord('post', { title: 'Hello' }); store.createRecord('post', { title: 'World' }); - let posts = store.peekAll('post'); + const posts = store.peekAll('post'); adapter.createRecord = function (store, type, snapshot) { return Promise.reject(); @@ -63,13 +63,13 @@ module('integration/records/collection_save - Save Collection of Records', funct }); test('Retry is allowed in a failure handler', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.createRecord('post', { title: 'Hello' }); store.createRecord('post', { title: 'World' }); - let posts = store.peekAll('post'); + const posts = store.peekAll('post'); let count = 0; let id = 1; @@ -99,13 +99,13 @@ module('integration/records/collection_save - Save Collection of Records', funct test('Collection will reject save on invalid', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.createRecord('post', { title: 'Hello' }); store.createRecord('post', { title: 'World' }); - let posts = store.peekAll('post'); + const posts = store.peekAll('post'); adapter.createRecord = function (store, type, snapshot) { return Promise.reject({ title: 'invalid' }); diff --git a/tests/main/tests/integration/records/concurrent-save-test.ts b/tests/main/tests/integration/records/concurrent-save-test.ts index 9434b6b23e0..43eadb5012b 100644 --- a/tests/main/tests/integration/records/concurrent-save-test.ts +++ b/tests/main/tests/integration/records/concurrent-save-test.ts @@ -5,7 +5,7 @@ import { setupTest } from 'ember-qunit'; import type { Snapshot } from '@ember-data/legacy-compat/-private'; import Model, { attr } from '@ember-data/model'; import { createDeferred } from '@ember-data/request'; -import Store from '@ember-data/store'; +import type Store from '@ember-data/store'; module('Integration | Record | concurrent saves', function (hooks) { setupTest(hooks); diff --git a/tests/main/tests/integration/records/create-record-test.js b/tests/main/tests/integration/records/create-record-test.js index 6d9ae8ff332..1dc5dd95468 100644 --- a/tests/main/tests/integration/records/create-record-test.js +++ b/tests/main/tests/integration/records/create-record-test.js @@ -31,7 +31,7 @@ module('Store.createRecord() coverage', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('model:pet', Pet); store = owner.lookup('service:store'); @@ -57,7 +57,7 @@ module('Store.createRecord() coverage', function (hooks) { }); test('unloading a newly created a record with a sync belongsTo relationship', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -72,7 +72,7 @@ module('Store.createRecord() coverage', function (hooks) { }, }); - let pet = store.createRecord('pet', { + const pet = store.createRecord('pet', { name: 'Shen', owner: chris, }); @@ -92,7 +92,7 @@ module('Store.createRecord() coverage', function (hooks) { }); test('unloading a record with a sync hasMany relationship to a newly created record', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -107,7 +107,7 @@ module('Store.createRecord() coverage', function (hooks) { }, }); - let pet = store.createRecord('pet', { + const pet = store.createRecord('pet', { name: 'Shen', owner: chris, }); @@ -164,7 +164,7 @@ module('Store.createRecord() coverage', function (hooks) { }) ); - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -180,7 +180,7 @@ module('Store.createRecord() coverage', function (hooks) { }, }); - let shen = store.createRecord('pet', { + const shen = store.createRecord('pet', { name: 'Shen', bestHuman: chris, }); diff --git a/tests/main/tests/integration/records/delete-record-test.js b/tests/main/tests/integration/records/delete-record-test.js index 4ef3306ee42..85299c1b035 100644 --- a/tests/main/tests/integration/records/delete-record-test.js +++ b/tests/main/tests/integration/records/delete-record-test.js @@ -1,5 +1,3 @@ -/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "(adam|dave|cersei)" }]*/ - import EmberObject, { get } from '@ember/object'; import { settled } from '@ember/test-helpers'; @@ -52,8 +50,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); test('records should not be removed from record arrays just after deleting, but only after committing them', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function () { return Promise.resolve(); @@ -77,8 +75,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }, ], }); - let adam = store.peekRecord('person', 1); - let all = store.peekAll('person'); + const adam = store.peekRecord('person', 1); + const all = store.peekAll('person'); // pre-condition assert.strictEqual(all.length, 2, 'pre-condition: 2 records in array'); @@ -102,8 +100,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { this.owner.register('model:group', Group); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function () { return Promise.resolve(); @@ -140,8 +138,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { ], }); - let group = store.peekRecord('group', '1'); - let person = store.peekRecord('person', '1'); + const group = store.peekRecord('group', '1'); + const person = store.peekRecord('person', '1'); // Sanity Check we are in the correct state. assert.strictEqual(group.people.length, 2, 'expected 2 related records before delete'); @@ -153,8 +151,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); test('records can be deleted during record array enumeration', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function () { return Promise.resolve(); @@ -197,8 +195,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); test('Deleting an invalid newly created record should remove it from the store', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function () { return Promise.reject( @@ -214,7 +212,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { ); }; - let record = store.createRecord('person', { name: 'pablobm' }); + const record = store.createRecord('person', { name: 'pablobm' }); // Invalidate the record to put it in the `root.loaded.created.invalid` state await record.save().catch(() => {}); @@ -226,7 +224,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { ); assert.strictEqual(get(store.peekAll('person'), 'length'), 1, 'The new person should be in the store'); - let identifier = recordIdentifierFor(record); + const identifier = recordIdentifierFor(record); const cache = store.cache; record.deleteRecord(); @@ -236,8 +234,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); test('Destroying an invalid newly created record should remove it from the store', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function () { assert.fail("The adapter's deletedRecord method should not be called when the record was created locally."); @@ -257,7 +255,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { ); }; - let record = store.createRecord('person', { name: 'pablobm' }); + const record = store.createRecord('person', { name: 'pablobm' }); // Invalidate the record to put it in the `root.loaded.created.invalid` state await record.save().catch(() => {}); @@ -269,7 +267,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { ); assert.strictEqual(get(store.peekAll('person'), 'length'), 1, 'The new person should be in the store'); - let identifier = recordIdentifierFor(record); + const identifier = recordIdentifierFor(record); const cache = store.cache; await record.destroyRecord(); @@ -279,11 +277,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); test('Will resolve destroy and save in same loop', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - - let adam, dave; - let promises; + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); assert.expect(1); @@ -297,17 +292,17 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); }; - adam = store.createRecord('person', { name: 'Adam Sunderland' }); - dave = store.createRecord('person', { name: 'Dave Sunderland' }); + const adam = store.createRecord('person', { name: 'Adam Sunderland' }); + const dave = store.createRecord('person', { name: 'Dave Sunderland' }); - promises = [adam.destroyRecord(), dave.save()]; + const promises = [adam.destroyRecord(), dave.save()]; await Promise.all(promises); }); test('Calling save on a newly created then deleted record should not error', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function () { assert.fail('We should not call adapter.createRecord on save'); @@ -319,11 +314,11 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { assert.fail('We should not call adapter.deleteRecord on save'); }; - let record = store.createRecord('person', { name: 'pablobm' }); + const record = store.createRecord('person', { name: 'pablobm' }); assert.strictEqual(get(store.peekAll('person'), 'length'), 1, 'The new person should be in the store'); - let identifier = recordIdentifierFor(record); + const identifier = recordIdentifierFor(record); const cache = store.cache; record.deleteRecord(); @@ -335,8 +330,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); test('Calling unloadRecord on a newly created then deleted record should not error', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function () { assert.fail('We should not call adapter.createRecord on save'); @@ -348,11 +343,11 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { assert.fail('We should not call adapter.deleteRecord on save'); }; - let record = store.createRecord('person', { name: 'pablobm' }); + const record = store.createRecord('person', { name: 'pablobm' }); assert.strictEqual(get(store.peekAll('person'), 'length'), 1, 'The new person should be in the store'); - let identifier = recordIdentifierFor(record); + const identifier = recordIdentifierFor(record); const cache = store.cache; record.deleteRecord(); @@ -366,9 +361,6 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { }); test('Records with an async hasMany can be pushed again after they were destroyed on client side', async function (assert) { - let group; - let employee; - class Company extends Model { @attr('string') name; toString() { @@ -391,8 +383,8 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { this.owner.register('model:group', Group); this.owner.register('model:employee', Employee); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function () { return Promise.resolve(); @@ -443,7 +435,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { store.push(structuredClone(jsonEmployee)); store.push(structuredClone(jsonGroup)); - group = store.peekRecord('group', '1'); + let group = store.peekRecord('group', '1'); const groupCompany = await group.company; // Sanity Check @@ -451,7 +443,7 @@ module('integration/deletedRecord - Deleting Records', function (hooks) { assert.strictEqual(groupCompany.name, 'Inc.', 'group belongs to our company'); assert.strictEqual(group.employees.length, 1, 'expected 1 related record before delete'); const employees = await group.employees; - employee = employees.at(0); + const employee = employees.at(0); assert.strictEqual(employee.name, 'Adam Sunderland', 'expected related records to be loaded'); await group.destroyRecord(); diff --git a/tests/main/tests/integration/records/edit-record-test.js b/tests/main/tests/integration/records/edit-record-test.js index 55804918ef0..c983046f089 100644 --- a/tests/main/tests/integration/records/edit-record-test.js +++ b/tests/main/tests/integration/records/edit-record-test.js @@ -27,7 +27,7 @@ module('Editing a Record', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('model:pet', Pet); store = owner.lookup('service:store'); @@ -110,7 +110,7 @@ module('Editing a Record', function (hooks) { }); test('Change parent relationship then unload original child', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -123,7 +123,7 @@ module('Editing a Record', function (hooks) { }, }); - let john = store.push({ + const john = store.push({ data: { id: '2', type: 'person', @@ -136,7 +136,7 @@ module('Editing a Record', function (hooks) { }, }); - let shen = store.push({ + const shen = store.push({ data: { id: '3', type: 'pet', @@ -152,7 +152,7 @@ module('Editing a Record', function (hooks) { }, }); - let rocky = store.push({ + const rocky = store.push({ data: { id: '4', type: 'pet', @@ -191,7 +191,7 @@ module('Editing a Record', function (hooks) { module('Simple relationship addition case', function () { module('Adding a sync belongsTo relationship to a record', function () { test('We can add to a record', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -204,7 +204,7 @@ module('Editing a Record', function (hooks) { }, }); - let pet = store.push({ + const pet = store.push({ data: { id: '1', type: 'pet', @@ -233,12 +233,12 @@ module('Editing a Record', function (hooks) { }); test('We can add a new record to a record', async function (assert) { - let chris = store.createRecord('person', { + const chris = store.createRecord('person', { name: 'Chris', pets: [], }); - let pet = store.push({ + const pet = store.push({ data: { id: '1', type: 'pet', @@ -267,12 +267,12 @@ module('Editing a Record', function (hooks) { }); test('We can add a new record to a new record', async function (assert) { - let chris = store.createRecord('person', { + const chris = store.createRecord('person', { name: 'Chris', pets: [], }); - let pet = store.createRecord('pet', { + const pet = store.createRecord('pet', { name: 'Shen', owner: null, }); @@ -293,7 +293,7 @@ module('Editing a Record', function (hooks) { }); test('We can add to a new record', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -306,7 +306,7 @@ module('Editing a Record', function (hooks) { }, }); - let pet = store.createRecord('pet', { + const pet = store.createRecord('pet', { name: 'Shen', owner: null, }); @@ -327,7 +327,7 @@ module('Editing a Record', function (hooks) { }); test('Change parent relationship and unload original parent', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -343,7 +343,7 @@ module('Editing a Record', function (hooks) { }, }); - let john = store.push({ + const john = store.push({ data: { id: '2', type: 'person', @@ -356,7 +356,7 @@ module('Editing a Record', function (hooks) { }, }); - let shen = store.push({ + const shen = store.push({ data: { id: '3', type: 'pet', @@ -372,7 +372,7 @@ module('Editing a Record', function (hooks) { }, }); - let rocky = store.push({ + const rocky = store.push({ data: { id: '4', type: 'pet', @@ -415,7 +415,7 @@ module('Editing a Record', function (hooks) { module('Adding an async belongsTo relationship to a record', function () { test('We can add to a record', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -428,7 +428,7 @@ module('Editing a Record', function (hooks) { }, }); - let james = store.push({ + const james = store.push({ data: { id: '1', type: 'person', @@ -459,7 +459,7 @@ module('Editing a Record', function (hooks) { }); test('We can add a new record to a record', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { id: '1', type: 'person', @@ -472,7 +472,7 @@ module('Editing a Record', function (hooks) { }, }); - let james = store.createRecord('person', { + const james = store.createRecord('person', { name: 'James', bestFriend: null, }); @@ -495,12 +495,12 @@ module('Editing a Record', function (hooks) { }); test('We can add a new record to a new record', async function (assert) { - let chris = store.createRecord('person', { + const chris = store.createRecord('person', { name: 'Chris', bestFriend: null, }); - let james = store.createRecord('person', { + const james = store.createRecord('person', { name: 'James', bestFriend: null, }); @@ -523,12 +523,12 @@ module('Editing a Record', function (hooks) { }); test('We can add to a new record', async function (assert) { - let chris = store.createRecord('person', { + const chris = store.createRecord('person', { name: 'Chris', bestFriend: null, }); - let james = store.push({ + const james = store.push({ data: { id: '1', type: 'person', diff --git a/tests/main/tests/integration/records/error-test.js b/tests/main/tests/integration/records/error-test.js index 73389e69f18..639d90caffd 100644 --- a/tests/main/tests/integration/records/error-test.js +++ b/tests/main/tests/integration/records/error-test.js @@ -21,7 +21,7 @@ module('integration/records/error', function (hooks) { this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -34,7 +34,7 @@ module('integration/records/error', function (hooks) { }, }); - let person = store.peekRecord('person', 'wat'); + const person = store.peekRecord('person', 'wat'); person.setProperties({ firstName: null, @@ -77,9 +77,9 @@ module('integration/records/error', function (hooks) { this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: 'wat', firstName: 'Yehuda', lastName: 'Katz', @@ -126,9 +126,9 @@ module('integration/records/error', function (hooks) { this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: 'wat', firstName: 'Yehuda', }); @@ -160,9 +160,9 @@ module('integration/records/error', function (hooks) { this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { + const person = store.createRecord('person', { id: 'wat', firstName: 'Yehuda', }); @@ -193,8 +193,8 @@ module('integration/records/error', function (hooks) { this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = () => { return Promise.reject( @@ -216,7 +216,7 @@ module('integration/records/error', function (hooks) { try { person = await person.save(); } catch (_error) { - let errors = person.errors; + const errors = person.errors; assert.strictEqual(errors.length, 2, 'Adds two errors to the model'); assert.true(errors.has('firstName'), 'firstName is included in the errors object'); diff --git a/tests/main/tests/integration/records/load-test.js b/tests/main/tests/integration/records/load-test.js index ff7f6a99a0d..f45b2e04910 100644 --- a/tests/main/tests/integration/records/load-test.js +++ b/tests/main/tests/integration/records/load-test.js @@ -36,7 +36,7 @@ module('integration/load - Loading Records', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); store = owner.lookup('service:store'); }); @@ -160,7 +160,7 @@ module('integration/load - Loading Records', function (hooks) { }); test('Empty records remain in the empty state while data is being fetched', async function (assert) { - let payloads = [ + const payloads = [ { data: { type: 'person', @@ -215,7 +215,7 @@ module('integration/load - Loading Records', function (hooks) { 'adapter:application', JSONAPIAdapter.extend({ findRecord() { - let payload = payloads.shift(); + const payload = payloads.shift(); if (payload === undefined) { return Promise.reject(new Error('Invalid Request')); @@ -234,7 +234,7 @@ module('integration/load - Loading Records', function (hooks) { }) ); - let identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); + const identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); const instanceCache = store._instanceCache; let cache = store.cache; @@ -246,7 +246,7 @@ module('integration/load - Loading Records', function (hooks) { // test that during the initial load our state is correct assert.true(_isLoading(instanceCache, identifier), 'awaiting first fetch: We have now triggered a load'); - let record = await recordPromise; + const record = await recordPromise; // test that after the initial load our state is correct cache = store.cache; @@ -254,13 +254,13 @@ module('integration/load - Loading Records', function (hooks) { assert.false(_isLoading(instanceCache, identifier), 'after first fetch: We have loaded'); assert.false(record.isReloading, 'after first fetch: We are not reloading'); - let bestFriend = await record.bestFriend; - let trueBestFriend = await bestFriend.bestFriend; + const bestFriend = await record.bestFriend; + const trueBestFriend = await bestFriend.bestFriend; // shen is our retainer for the record we are testing // that ensures unloadRecord later in this test does not fully // discard the identifier - let shen = store.peekRecord('person', '2'); + const shen = store.peekRecord('person', '2'); assert.strictEqual(bestFriend, shen, 'Precond: bestFriend is correct'); assert.strictEqual(trueBestFriend, record, 'Precond: bestFriend of bestFriend is correct'); diff --git a/tests/main/tests/integration/records/new-record-unload-test.js b/tests/main/tests/integration/records/new-record-unload-test.js index 5d422308ec2..d0441099380 100644 --- a/tests/main/tests/integration/records/new-record-unload-test.js +++ b/tests/main/tests/integration/records/new-record-unload-test.js @@ -36,10 +36,10 @@ module('Integration | Records | New Record Unload', function (hooks) { }, }, }); - let Pat = store.createRecord('person', { name: 'Patrick Wachter' }); + const Pat = store.createRecord('person', { name: 'Patrick Wachter' }); const friends = Matt.hasMany('friends').value(); friends.push(Pat); - let people = store.peekAll('person'); + const people = store.peekAll('person'); assert.strictEqual(friends.length, 1, 'Matt has friends'); assert.strictEqual(people.length, 2, 'precond - two people records in the store'); @@ -148,10 +148,10 @@ module('Integration | Records | New Record Unload', function (hooks) { }, }, }); - let Pat = store.createRecord('person', { name: 'Patrick Wachter' }); + const Pat = store.createRecord('person', { name: 'Patrick Wachter' }); const friends = Matt.hasMany('friends').value(); friends.push(Pat); - let people = store.peekAll('person'); + const people = store.peekAll('person'); assert.strictEqual(friends.length, 1, 'Matt has friends'); assert.strictEqual(people.length, 2, 'precond - two people records in the store'); @@ -191,10 +191,10 @@ module('Integration | Records | New Record Unload', function (hooks) { }, }, }); - let Pat = store.createRecord('person', { name: 'Patrick Wachter' }); + const Pat = store.createRecord('person', { name: 'Patrick Wachter' }); const friends = Matt.hasMany('friends').value(); friends.push(Pat); - let people = store.peekAll('person'); + const people = store.peekAll('person'); assert.strictEqual(friends.length, 1, 'Matt has friends'); assert.strictEqual(people.length, 2, 'precond - two people records in the store'); @@ -241,10 +241,10 @@ module('Integration | Records | New Record Unload', function (hooks) { }, }, }); - let Pat = store.createRecord('person', { name: 'Patrick Wachter' }); + const Pat = store.createRecord('person', { name: 'Patrick Wachter' }); const friends = Matt.hasMany('friends').value(); friends.push(Pat); - let people = store.peekAll('person'); + const people = store.peekAll('person'); assert.strictEqual(friends.length, 1, 'Matt has friends'); assert.strictEqual(people.length, 2, 'precond - two people records in the store'); @@ -291,10 +291,10 @@ module('Integration | Records | New Record Unload', function (hooks) { }, }, }); - let Pat = store.createRecord('person', { name: 'Patrick Wachter' }); + const Pat = store.createRecord('person', { name: 'Patrick Wachter' }); const friends = Matt.hasMany('friends').value(); friends.push(Pat); - let people = store.peekAll('person'); + const people = store.peekAll('person'); assert.strictEqual(friends.length, 1, 'Matt has friends'); assert.strictEqual(people.length, 2, 'precond - two people records in the store'); @@ -341,10 +341,10 @@ module('Integration | Records | New Record Unload', function (hooks) { }, }, }); - let Pat = store.createRecord('person', { name: 'Patrick Wachter' }); + const Pat = store.createRecord('person', { name: 'Patrick Wachter' }); const friends = Matt.hasMany('friends').value(); friends.push(Pat); - let people = store.peekAll('person'); + const people = store.peekAll('person'); assert.strictEqual(friends.length, 1, 'Matt has friends'); assert.strictEqual(people.length, 2, 'precond - two people records in the store'); @@ -396,10 +396,10 @@ module('Integration | Records | New Record Unload', function (hooks) { }, }, }); - let Pat = store.createRecord('person', { name: 'Patrick Wachter' }); + const Pat = store.createRecord('person', { name: 'Patrick Wachter' }); const friends = Matt.hasMany('friends').value(); friends.push(Pat); - let people = store.peekAll('person'); + const people = store.peekAll('person'); assert.strictEqual(friends.length, 1, 'Matt has friends'); assert.strictEqual(people.length, 2, 'precond - two people records in the store'); diff --git a/tests/main/tests/integration/records/property-changes-test.js b/tests/main/tests/integration/records/property-changes-test.js index 19f459a04cf..e4a735b2e5c 100644 --- a/tests/main/tests/integration/records/property-changes-test.js +++ b/tests/main/tests/integration/records/property-changes-test.js @@ -23,7 +23,7 @@ module('integration/records/property-changes - Property changes', function (hook test('Calling push with partial records trigger observers for just those attributes that changed', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -60,7 +60,7 @@ module('integration/records/property-changes - Property changes', function (hook test('Calling push does not trigger observers for locally changed attributes with the same value', async function (assert) { assert.expect(0); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var person; @@ -101,8 +101,8 @@ module('integration/records/property-changes - Property changes', function (hook assert.expect(1); var person; - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.updateRecord = function (store, type, snapshot) { return Promise.resolve({ data: { id: 'wat', type: 'person', attributes: { 'last-name': 'Katz' } } }); @@ -135,7 +135,7 @@ module('integration/records/property-changes - Property changes', function (hook test('store.push should not override a modified attribute', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const person = store.push({ data: { diff --git a/tests/main/tests/integration/records/relationship-changes-test.js b/tests/main/tests/integration/records/relationship-changes-test.js index 425d459b304..ca899a4f49c 100644 --- a/tests/main/tests/integration/records/relationship-changes-test.js +++ b/tests/main/tests/integration/records/relationship-changes-test.js @@ -213,7 +213,7 @@ module('integration/records/relationship-changes - Relationship changes', functi test('Calling push with relationship does not trigger observers if the relationship was not changed', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); let observerCount = 0; const person = store.push({ diff --git a/tests/main/tests/integration/records/reload-test.js b/tests/main/tests/integration/records/reload-test.js index ee6e9f3a10d..1e267eb9eeb 100644 --- a/tests/main/tests/integration/records/reload-test.js +++ b/tests/main/tests/integration/records/reload-test.js @@ -24,7 +24,7 @@ module('integration/reload - Reloading Records', function (hooks) { lastName; } - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register( 'serializer:application', @@ -39,7 +39,7 @@ module('integration/reload - Reloading Records', function (hooks) { test("When a single record is requested, the adapter's find method should be called unless it's loaded.", async function (assert) { let count = 0; - let reloadOptions = { + const reloadOptions = { adapterOptions: { makeSnazzy: true, }, @@ -73,12 +73,12 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); assert.strictEqual(get(person, 'name'), 'Tom Dale', 'The person is loaded with the right name'); assert.true(get(person, 'isLoaded'), 'The person is now loaded'); - let promise = person.reload(reloadOptions); + const promise = person.reload(reloadOptions); assert.true(get(person, 'isReloading'), 'The person is now reloading'); @@ -92,7 +92,7 @@ module('integration/reload - Reloading Records', function (hooks) { }); test('When a record is reloaded and fails, it can try again', async function (assert) { - let tom = store.push({ + const tom = store.push({ data: { type: 'person', id: '1', @@ -133,7 +133,7 @@ module('integration/reload - Reloading Records', function (hooks) { assert.true(tom.isError, 'Tom is now errored'); assert.false(tom.isReloading, 'Tom is no longer reloading'); - let person = await tom.reload(); + const person = await tom.reload(); assert.strictEqual(person, tom, 'The resolved value is the record'); assert.false(tom.isError, 'Tom is no longer errored'); @@ -178,7 +178,7 @@ module('integration/reload - Reloading Records', function (hooks) { store.push(getTomDale()); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); person.addObserver('isLoaded', isLoadedDidChange); assert.true(get(person, 'isLoaded'), 'The person is loaded'); @@ -207,7 +207,7 @@ module('integration/reload - Reloading Records', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:tag', Tag); - let tagsById = { 1: 'hipster', 2: 'hair' }; + const tagsById = { 1: 'hipster', 2: 'hair' }; this.owner.register( 'adapter:application', @@ -241,10 +241,9 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let tom; let person = await store.findRecord('person', '1'); - tom = person; + const tom = person; assert.strictEqual(person.name, 'Tom', 'precond'); let tags = await person.tags; @@ -295,7 +294,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -317,9 +316,9 @@ module('integration/reload - Reloading Records', function (hooks) { ], }); - let ownerRef = shen.belongsTo('owner'); - let owner = shen.owner; - let ownerViaRef = await ownerRef.reload(); + const ownerRef = shen.belongsTo('owner'); + const owner = shen.owner; + const ownerViaRef = await ownerRef.reload(); assert.strictEqual(owner, ownerViaRef, 'We received the same reference via reload'); }); @@ -352,7 +351,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -365,9 +364,9 @@ module('integration/reload - Reloading Records', function (hooks) { }, }); - let ownerRef = shen.belongsTo('owner'); - let ownerViaRef = await ownerRef.reload(); - let owner = shen.owner; + const ownerRef = shen.belongsTo('owner'); + const ownerViaRef = await ownerRef.reload(); + const owner = shen.owner; assert.strictEqual(owner, ownerViaRef, 'We received the same reference via reload'); }); @@ -400,7 +399,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -422,9 +421,9 @@ module('integration/reload - Reloading Records', function (hooks) { ], }); - let ownersRef = shen.hasMany('owners'); - let owners = shen.owners; - let ownersViaRef = await ownersRef.reload(); + const ownersRef = shen.hasMany('owners'); + const owners = shen.owners; + const ownersViaRef = await ownersRef.reload(); assert.strictEqual(owners.at(0), ownersViaRef.at(0), 'We received the same reference via reload'); }); @@ -457,7 +456,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -470,9 +469,9 @@ module('integration/reload - Reloading Records', function (hooks) { }, }); - let ownersRef = shen.hasMany('owners'); - let ownersViaRef = await ownersRef.reload(); - let owners = shen.owners; + const ownersRef = shen.hasMany('owners'); + const ownersViaRef = await ownersRef.reload(); + const owners = shen.owners; assert.strictEqual(owners.at(0), ownersViaRef.at(0), 'We received the same reference via reload'); }); @@ -507,7 +506,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -532,9 +531,9 @@ module('integration/reload - Reloading Records', function (hooks) { ], }); - let ownerRef = shen.belongsTo('owner'); - let owner = shen.owner; - let ownerViaRef = await ownerRef.reload(); + const ownerRef = shen.belongsTo('owner'); + const owner = shen.owner; + const ownerViaRef = await ownerRef.reload(); assert.strictEqual(owner, ownerViaRef, 'We received the same reference via reload'); }); @@ -567,7 +566,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -583,9 +582,9 @@ module('integration/reload - Reloading Records', function (hooks) { }, }); - let ownerRef = shen.belongsTo('owner'); - let ownerViaRef = await ownerRef.reload(); - let owner = shen.owner; + const ownerRef = shen.belongsTo('owner'); + const ownerViaRef = await ownerRef.reload(); + const owner = shen.owner; assert.strictEqual(owner, ownerViaRef, 'We received the same reference via reload'); }); @@ -620,7 +619,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -645,9 +644,9 @@ module('integration/reload - Reloading Records', function (hooks) { ], }); - let ownersRef = shen.hasMany('owners'); - let owners = shen.owners; - let ownersViaRef = await ownersRef.reload(); + const ownersRef = shen.hasMany('owners'); + const owners = shen.owners; + const ownersViaRef = await ownersRef.reload(); assert.strictEqual(owners.at(0), ownersViaRef.at(0), 'We received the same reference via reload'); }); @@ -682,7 +681,7 @@ module('integration/reload - Reloading Records', function (hooks) { }) ); - let shen = store.push({ + const shen = store.push({ data: { type: 'pet', id: '1', @@ -698,9 +697,9 @@ module('integration/reload - Reloading Records', function (hooks) { }, }); - let ownersRef = shen.hasMany('owners'); - let ownersViaRef = await ownersRef.reload(); - let owners = shen.owners; + const ownersRef = shen.hasMany('owners'); + const ownersViaRef = await ownersRef.reload(); + const owners = shen.owners; assert.strictEqual(owners.at(0), ownersViaRef.at(0), 'We received the same reference via reload'); }); diff --git a/tests/main/tests/integration/records/rematerialize-test.js b/tests/main/tests/integration/records/rematerialize-test.js index c47869e9e1e..fdcd86153f3 100644 --- a/tests/main/tests/integration/records/rematerialize-test.js +++ b/tests/main/tests/integration/records/rematerialize-test.js @@ -36,7 +36,7 @@ module('integration/unload - Rematerializing Unloaded Records', function (hooks) // disable background reloading so we do not re-create the relationship. adapter.shouldBackgroundReloadRecord = () => false; - let adam = store.push({ + const adam = store.push({ data: { type: 'person', id: '1', @@ -98,7 +98,7 @@ module('integration/unload - Rematerializing Unloaded Records', function (hooks) }, }); - let rematerializedPerson = lotus.person; + const rematerializedPerson = lotus.person; assert.strictEqual(rematerializedPerson.id, '1'); assert.strictEqual(rematerializedPerson.name, 'Adam Sunderland'); assert.strictEqual(rematerializedPerson, newAdam); @@ -124,8 +124,8 @@ module('integration/unload - Rematerializing Unloaded Records', function (hooks) this.owner.register('model:person', Person); this.owner.register('model:boat', Boat); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); // disable background reloading so we do not re-create the relationship. adapter.shouldBackgroundReloadRecord = () => false; @@ -174,7 +174,7 @@ module('integration/unload - Rematerializing Unloaded Records', function (hooks) }; }; - let adam = store.push({ + const adam = store.push({ data: { type: 'person', id: '1', @@ -192,7 +192,7 @@ module('integration/unload - Rematerializing Unloaded Records', function (hooks) }, }); - let [boaty] = store.push({ + const [boaty] = store.push({ data: [deepCopy(BOAT_ONE), deepCopy(BOAT_TWO)], }); @@ -220,7 +220,7 @@ module('integration/unload - Rematerializing Unloaded Records', function (hooks) // cause a rematerialization, this should also cause us to fetch boat '1' again boats = await adam.boats; - let rematerializedBoaty = boats.at(1); + const rematerializedBoaty = boats.at(1); assert.ok(!!rematerializedBoaty, 'We have a boat!'); assert.strictEqual(adam.boats.length, 2, 'boats.length correct after rematerialization'); diff --git a/tests/main/tests/integration/records/save-test.js b/tests/main/tests/integration/records/save-test.js index 533d7276228..83bb9adfc15 100644 --- a/tests/main/tests/integration/records/save-test.js +++ b/tests/main/tests/integration/records/save-test.js @@ -25,19 +25,19 @@ module('integration/records/save - Save Record', function (hooks) { }); test('Will resolve save on success', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); const deferred = createDeferred(); adapter.createRecord = function (store, type, snapshot) { return deferred.promise; }; - let saved = post.save(); + const saved = post.save(); deferred.resolve({ data: { id: '123', type: 'post' } }); - let model = await saved; + const model = await saved; assert.ok(true, 'save operation was resolved'); assert.strictEqual(saved.id, undefined, `.id is undefined after save resolves`); assert.strictEqual(model.id, '123', `record.id is '123' after save resolves`); @@ -45,12 +45,12 @@ module('integration/records/save - Save Record', function (hooks) { }); test('Will reject save on error', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); adapter.createRecord = function (store, type, snapshot) { - let error = new InvalidError([{ title: 'not valid' }]); + const error = new InvalidError([{ title: 'not valid' }]); return Promise.reject(error); }; @@ -90,14 +90,14 @@ module('integration/records/save - Save Record', function (hooks) { }); test('Retry is allowed in a failure handler', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); var count = 0; adapter.createRecord = function (store, type, snapshot) { - let error = new InvalidError([{ title: 'not valid' }]); + const error = new InvalidError([{ title: 'not valid' }]); if (count++ === 0) { return Promise.reject(error); @@ -117,9 +117,9 @@ module('integration/records/save - Save Record', function (hooks) { test('Repeated failed saves keeps the record in uncommitted state', async function (assert) { assert.expect(4); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); adapter.createRecord = function (store, type, snapshot) { return Promise.reject(); @@ -145,12 +145,12 @@ module('integration/records/save - Save Record', function (hooks) { test('Repeated failed saves with invalid error marks the record as invalid', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); adapter.createRecord = function (store, type, snapshot) { - let error = new InvalidError([ + const error = new InvalidError([ { detail: 'is invalid', source: { pointer: 'data/attributes/title' }, @@ -177,12 +177,12 @@ module('integration/records/save - Save Record', function (hooks) { test('Repeated failed saves with invalid error without payload marks the record as invalid', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); adapter.createRecord = function (store, type, snapshot) { - let error = new InvalidError(); + const error = new InvalidError(); return Promise.reject(error); }; @@ -203,9 +203,9 @@ module('integration/records/save - Save Record', function (hooks) { test('Will reject save on invalid', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); adapter.createRecord = function (store, type, snapshot) { var error = new InvalidError([{ title: 'not valid' }]); @@ -247,9 +247,9 @@ module('integration/records/save - Save Record', function (hooks) { test('Will error when saving after unloading record via the store', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); adapter.createRecord = function (store, type, snapshot) { return { @@ -272,9 +272,9 @@ module('integration/records/save - Save Record', function (hooks) { test('Will error when saving after unloading record', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let post = store.createRecord('post', { title: 'toto' }); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const post = store.createRecord('post', { title: 'toto' }); adapter.createRecord = function (store, type, snapshot) { return { diff --git a/tests/main/tests/integration/records/unload-test.js b/tests/main/tests/integration/records/unload-test.js index 6767aeb72de..6903bcf2d22 100644 --- a/tests/main/tests/integration/records/unload-test.js +++ b/tests/main/tests/integration/records/unload-test.js @@ -120,7 +120,7 @@ module('integration/unload - Unloading Records', function (hooks) { let store, adapter; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register(`model:person`, Person); owner.register(`model:car`, Car); @@ -238,7 +238,7 @@ module('integration/unload - Unloading Records', function (hooks) { }); car = store.peekRecord('car', 1); - let person = car.person; + const person = car.person; assert.ok(!!car, 'We have a car'); assert.notOk(person, 'We dont have a person'); @@ -638,7 +638,7 @@ module('integration/unload - Unloading Records', function (hooks) { }, ], }); - let all = store.peekAll('person'); + const all = store.peekAll('person'); assert.strictEqual(all.length, 2); @@ -687,14 +687,14 @@ module('integration/unload - Unloading Records', function (hooks) { }); const all2 = store.peekAll('person'); assert.strictEqual(all2.length, 1, 'after next push: record array has one item'); - // eslint-disable-next-line qunit/no-ok-equality + assert.true(all === all2, 'after next push: record array is the same'); }); test('unloadAll(type) does not leave stranded internalModels in relationships (rediscover via store.push)', async function (assert) { assert.expect(16); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -710,16 +710,16 @@ module('integration/unload - Unloading Records', function (hooks) { included: [makeBoatOneForPersonOne()], }); - let boat = store.peekRecord('boat', '1'); - let relationshipState = person.hasMany('boats').hasManyRelationship; + const boat = store.peekRecord('boat', '1'); + const relationshipState = person.hasMany('boats').hasManyRelationship; // ensure we loaded the people and boats assert.notStrictEqual(store.peekRecord('person', '1'), null); assert.notStrictEqual(store.peekRecord('boat', '1'), null); // ensure the relationship was established (we reach through the async proxy here) - let peopleBoats = await person.boats; - let boatPerson = await boat.person; + const peopleBoats = await person.boats; + const boatPerson = await boat.person; assert.strictEqual(relationshipState.remoteState.length, 1, 'remoteMembers size should be 1'); assert.strictEqual(relationshipState.additions, null, 'additions should be empty'); @@ -760,7 +760,7 @@ module('integration/unload - Unloading Records', function (hooks) { }); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -776,15 +776,15 @@ module('integration/unload - Unloading Records', function (hooks) { included: [makeBoatOneForPersonOne()], }); - let boat = store.peekRecord('boat', '1'); - let relationshipState = person.hasMany('boats').hasManyRelationship; + const boat = store.peekRecord('boat', '1'); + const relationshipState = person.hasMany('boats').hasManyRelationship; // ensure we loaded the people and boats assert.notStrictEqual(store.peekRecord('person', '1'), null); assert.notStrictEqual(store.peekRecord('boat', '1'), null); - let peopleBoats = await person.boats; - let boatPerson = await boat.person; + const peopleBoats = await person.boats; + const boatPerson = await boat.person; assert.strictEqual(relationshipState.remoteState.length, 1, 'remoteMembers size should be 1'); assert.strictEqual(relationshipState.additions, null, 'additions should be empty'); @@ -813,7 +813,7 @@ module('integration/unload - Unloading Records', function (hooks) { }); test('(regression) unloadRecord followed by push in the same run-loop', async function (assert) { - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -830,15 +830,15 @@ module('integration/unload - Unloading Records', function (hooks) { }); let boat = store.peekRecord('boat', '1'); - let relationshipState = person.hasMany('boats').hasManyRelationship; + const relationshipState = person.hasMany('boats').hasManyRelationship; // ensure we loaded the people and boats assert.notStrictEqual(store.peekRecord('person', '1'), null); assert.notStrictEqual(store.peekRecord('boat', '1'), null); // ensure the relationship was established - let peopleBoats = await person.boats; - let boatPerson = await boat.person; + const peopleBoats = await person.boats; + const boatPerson = await boat.person; assert.deepEqual(idsFromArr(relationshipState.remoteState), ['1'], 'remoteMembers size should be 1'); assert.deepEqual(idsFromArr(relationshipState.localState), ['1'], 'localMembers size should be 1'); @@ -857,7 +857,7 @@ module('integration/unload - Unloading Records', function (hooks) { data: makeBoatOneForPersonOne(), }); - let reloadedBoat = store.peekRecord('boat', '1'); + const reloadedBoat = store.peekRecord('boat', '1'); assert.deepEqual(idsFromArr(relationshipState.remoteState), ['1'], 'remoteMembers size should be 1'); assert.deepEqual(idsFromArr(relationshipState.localState), ['1'], 'localMembers size should be 1'); @@ -886,10 +886,9 @@ module('integration/unload - Unloading Records', function (hooks) { // here, we will dematerialize the record, but push it back into the store // all in the same run-loop! // effectively this tests that our destroySync is not stupid - let newPerson; await settled(); person.unloadRecord(); - newPerson = store.push({ + const newPerson = store.push({ data: { type: 'person', id: '1', @@ -920,7 +919,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; // populate initial record - let record = store.push({ + const record = store.push({ data: { type: 'person', id: '1', @@ -997,7 +996,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; // populate initial record - let record = store.push({ + const record = store.push({ data: { type: 'person', id: '1', @@ -1027,7 +1026,7 @@ module('integration/unload - Unloading Records', function (hooks) { ], }); - let identifier = recordIdentifierFor(record); + const identifier = recordIdentifierFor(record); const cache = store.cache; assert.strictEqual(record.currentState.stateName, 'root.loaded.saved', 'We are loaded initially'); @@ -1063,7 +1062,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; // populate initial record - let record = store.push({ + const record = store.push({ data: { type: 'person', id: '1', @@ -1085,7 +1084,7 @@ module('integration/unload - Unloading Records', function (hooks) { ], }); - let identifier = recordIdentifierFor(record); + const identifier = recordIdentifierFor(record); const cache = store.cache; const bike = store.peekRecord('bike', '1'); @@ -1138,7 +1137,7 @@ module('integration/unload - Unloading Records', function (hooks) { }, }); - let identifier = recordIdentifierFor(record); + const identifier = recordIdentifierFor(record); const cache = store.cache; assert.strictEqual(record.currentState.stateName, 'root.loaded.saved', 'We are loaded initially'); @@ -1213,7 +1212,7 @@ module('integration/unload - Unloading Records', function (hooks) { store.push(personData); - let adam = store.peekRecord('person', 1); + const adam = store.peekRecord('person', 1); assert.strictEqual(adam.cars.length, 0, 'cars hasMany starts off empty'); pushCar(); @@ -1248,7 +1247,7 @@ module('integration/unload - Unloading Records', function (hooks) { ], }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); let house = store.peekRecord('house', 2); assert.strictEqual(person.house.id, '2', 'initially relationship established lhs'); @@ -1322,9 +1321,9 @@ module('integration/unload - Unloading Records', function (hooks) { }); let person = store.peekRecord('person', 1); - let car2 = store.peekRecord('car', 2); - let car3 = store.peekRecord('car', 3); - let cars = person.cars; + const car2 = store.peekRecord('car', 2); + const car3 = store.peekRecord('car', 3); + const cars = person.cars; assert.false(cars.isDestroyed, 'ManyArray not destroyed'); assert.deepEqual( @@ -1421,10 +1420,10 @@ module('integration/unload - Unloading Records', function (hooks) { ], }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); let car2 = store.peekRecord('car', 2); - let car3 = store.peekRecord('car', 3); - let cars = person.cars; + const car3 = store.peekRecord('car', 3); + const cars = person.cars; assert.false(cars.isDestroyed, 'ManyArray not destroyed'); assert.deepEqual( @@ -1542,12 +1541,12 @@ module('integration/unload - Unloading Records', function (hooks) { ], }); - let person1 = store.peekRecord('person', 1); + const person1 = store.peekRecord('person', 1); let person2 = store.peekRecord('person', 2); - let group3 = store.peekRecord('group', 3); - let group4 = store.peekRecord('group', 4); - let p2groups = person2.groups; - let g3people = group3.people; + const group3 = store.peekRecord('group', 3); + const group4 = store.peekRecord('group', 4); + const p2groups = person2.groups; + const g3people = group3.people; assert.deepEqual( person1.groups.map((r) => r.id), @@ -1674,7 +1673,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = store.push({ + const person = store.push({ data: { id: '1', type: 'person', @@ -1752,7 +1751,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = store.push({ + const person = store.push({ data: { id: '1', type: 'person', @@ -1772,11 +1771,10 @@ module('integration/unload - Unloading Records', function (hooks) { }, }, }); - let boats, boat2, boat3; const asyncRecords = await person.boats; - boats = asyncRecords; - [boat2, boat3] = boats.slice(); + const boats = asyncRecords; + const [boat2, boat3] = boats.slice(); await Promise.all([boat2, boat3].map((b) => b.person)); assert.deepEqual(person.hasMany('boats').ids(), ['2', '3'], 'initially relationship established lhs'); @@ -1827,7 +1825,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = store.push({ + const person = store.push({ data: { id: '1', type: 'person', @@ -1850,6 +1848,7 @@ module('integration/unload - Unloading Records', function (hooks) { const boats = await person.boats; + // eslint-disable-next-line prefer-const let [boat2, boat3] = boats.slice(); await Promise.all([boat2.person, boat3.person]); @@ -1929,7 +1928,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let [person1, person2] = store.push({ + const [person1, person2] = store.push({ data: [ { id: '1', @@ -2020,7 +2019,7 @@ module('integration/unload - Unloading Records', function (hooks) { }); test('1 sync : 1 async unload sync side', async function (assert) { - let person = store.push({ + const person = store.push({ data: { id: '1', type: 'person', @@ -2122,8 +2121,8 @@ module('integration/unload - Unloading Records', function (hooks) { ], }); - let person = store.peekRecord('person', 1); - let book = store.peekRecord('book', 2); + const person = store.peekRecord('person', 1); + const book = store.peekRecord('book', 2); await book.person .then(() => { @@ -2177,10 +2176,10 @@ module('integration/unload - Unloading Records', function (hooks) { ], }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); let spoon2 = store.peekRecord('spoon', 2); - let spoon3 = store.peekRecord('spoon', 3); - let spoons = person.favoriteSpoons; + const spoon3 = store.peekRecord('spoon', 3); + const spoons = person.favoriteSpoons; assert.false(spoons.isDestroyed, 'ManyArray not destroyed'); assert.deepEqual( @@ -2273,7 +2272,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = store.push({ + const person = store.push({ data: { id: '1', type: 'person', @@ -2303,9 +2302,9 @@ module('integration/unload - Unloading Records', function (hooks) { }, ], }); - let spoon2 = store.peekRecord('spoon', '2'); - let spoon3 = store.peekRecord('spoon', '3'); - let spoons = person.favoriteSpoons; + const spoon2 = store.peekRecord('spoon', '2'); + const spoon3 = store.peekRecord('spoon', '3'); + const spoons = person.favoriteSpoons; assert.deepEqual( person.favoriteSpoons.map((r) => r.id), @@ -2363,7 +2362,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = store.push({ + const person = store.push({ data: { id: '1', type: 'person', @@ -2470,11 +2469,10 @@ module('integration/unload - Unloading Records', function (hooks) { }, }, }); - let shows, show2, show3; const asyncRecords = await person.favoriteShows; - shows = asyncRecords; - [show2, show3] = shows.slice(); + const shows = asyncRecords; + const [show2, show3] = shows.slice(); assert.deepEqual(person.hasMany('favoriteShows').ids(), ['2', '3'], 'initially relationship established lhs'); assert.strictEqual(show2.person.id, '1', 'initially relationship established rhs'); @@ -2557,7 +2555,7 @@ module('integration/unload - Unloading Records', function (hooks) { assert.strictEqual(snapshot.modelName, 'person', 'findHasMany(_, snapshot) is correct'); assert.strictEqual(link, 'boats', 'findHasMany(_, _, link) is correct'); - let relationships = { + const relationships = { person: { data: { type: 'person', @@ -2566,7 +2564,7 @@ module('integration/unload - Unloading Records', function (hooks) { }, }; - let data = [ + const data = [ { id: '3', type: 'boat', @@ -2587,7 +2585,7 @@ module('integration/unload - Unloading Records', function (hooks) { }; }; - let person = store.push({ + const person = store.push({ data: { id: '1', type: 'person', diff --git a/tests/main/tests/integration/references/belongs-to-test.js b/tests/main/tests/integration/references/belongs-to-test.js index b608133f8ec..0470ae7d651 100644 --- a/tests/main/tests/integration/references/belongs-to-test.js +++ b/tests/main/tests/integration/references/belongs-to-test.js @@ -37,9 +37,9 @@ module('integration/references/belongs-to', function (hooks) { }); testInDebug("record#belongsTo asserts when specified relationship doesn't exist", function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -54,9 +54,9 @@ module('integration/references/belongs-to', function (hooks) { testInDebug( "record#belongsTo asserts when the type of the specified relationship isn't the requested one", function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let family = store.push({ + const family = store.push({ data: { type: 'family', id: '1', @@ -70,9 +70,9 @@ module('integration/references/belongs-to', function (hooks) { ); test('record#belongsTo', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -84,7 +84,7 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); assert.strictEqual(familyReference.remoteType(), 'id'); assert.strictEqual(familyReference.type, 'family'); @@ -92,9 +92,9 @@ module('integration/references/belongs-to', function (hooks) { }); test('record#belongsTo for a linked reference', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -106,7 +106,7 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); assert.strictEqual(familyReference.remoteType(), 'link'); assert.strictEqual(familyReference.type, 'family'); @@ -114,9 +114,9 @@ module('integration/references/belongs-to', function (hooks) { }); test('BelongsToReference#meta() returns the most recent meta for the relationship', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -133,15 +133,15 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); assert.deepEqual(familyReference.meta(), { foo: true }); }); test('push(object)', async function (assert) { - let store = this.owner.lookup('service:store'); - let Family = store.modelFor('family'); + const store = this.owner.lookup('service:store'); + const Family = store.modelFor('family'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -153,9 +153,9 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); - let data = { + const data = { data: { type: 'family', id: '1', @@ -183,9 +183,9 @@ module('integration/references/belongs-to', function (hooks) { this.owner.register('model:family', Family); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -196,14 +196,14 @@ module('integration/references/belongs-to', function (hooks) { }, }, }); - let anotherPerson = { + const anotherPerson = { data: { type: 'person', id: '2', }, }; - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); await assert.expectAssertion(async function () { await familyReference.push(anotherPerson); @@ -226,32 +226,32 @@ module('integration/references/belongs-to', function (hooks) { this.owner.register('model:family', Family); this.owner.register('model:person', Person); this.owner.register('model:mafia-family', MafiaFamily); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', }, }); - let mafiaFamily = { + const mafiaFamily = { data: { type: 'mafia-family', id: '1', }, }; - let familyReference = person.belongsTo('family'); - let family = await familyReference.push(mafiaFamily); + const familyReference = person.belongsTo('family'); + const family = await familyReference.push(mafiaFamily); const record = store.peekRecord('mafia-family', '1'); assert.strictEqual(family, record); }); test('value() is null when reference is not yet loaded', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -263,14 +263,14 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); assert.strictEqual(familyReference.value(), null); }); test('value() returns the referenced record when loaded', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -281,20 +281,20 @@ module('integration/references/belongs-to', function (hooks) { }, }, }); - let family = store.push({ + const family = store.push({ data: { type: 'family', id: '1', }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); assert.strictEqual(familyReference.value(), family); }); test('value() returns the referenced record when loaded even if links are present', function (assert) { - let store = this.owner.lookup('service:store'); - let person = store.push({ + const store = this.owner.lookup('service:store'); + const person = store.push({ data: { type: 'person', id: '1', @@ -305,7 +305,7 @@ module('integration/references/belongs-to', function (hooks) { }, }, }); - let family = store.push({ + const family = store.push({ data: { type: 'family', id: '1', @@ -324,8 +324,8 @@ module('integration/references/belongs-to', function (hooks) { }); test('load() fetches the record', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -340,7 +340,7 @@ module('integration/references/belongs-to', function (hooks) { }); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -352,7 +352,7 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); const record = await familyReference.load({ adapterOptions }); @@ -360,8 +360,8 @@ module('integration/references/belongs-to', function (hooks) { }); test('load() fetches the record (sync belongsTo)', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -376,7 +376,7 @@ module('integration/references/belongs-to', function (hooks) { }); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -388,15 +388,15 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let teamReference = person.belongsTo('team'); + const teamReference = person.belongsTo('team'); const record = await teamReference.load({ adapterOptions }); assert.strictEqual(record.name, 'Tomsters'); }); test('load() fetches link when remoteType is link', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -413,7 +413,7 @@ module('integration/references/belongs-to', function (hooks) { }); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -425,7 +425,7 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); assert.strictEqual(familyReference.remoteType(), 'link'); await familyReference.load({ adapterOptions }).then(function (record) { @@ -434,8 +434,8 @@ module('integration/references/belongs-to', function (hooks) { }); test('meta can be retrieved, even if the fetched data is null', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -471,8 +471,8 @@ module('integration/references/belongs-to', function (hooks) { }); test('reload() - loads the record when not yet loaded', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -492,7 +492,7 @@ module('integration/references/belongs-to', function (hooks) { }); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -504,7 +504,7 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); await familyReference.reload({ adapterOptions }).then(function (record) { assert.strictEqual(get(record, 'name'), 'Coreleone'); @@ -512,8 +512,8 @@ module('integration/references/belongs-to', function (hooks) { }); test('reload() - reloads the record when already loaded', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -533,7 +533,7 @@ module('integration/references/belongs-to', function (hooks) { }); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -551,7 +551,7 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); await familyReference.reload({ adapterOptions }).then(function (record) { assert.strictEqual(get(record, 'name'), 'Coreleone'); @@ -559,8 +559,8 @@ module('integration/references/belongs-to', function (hooks) { }); test('reload() - uses link to reload record', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -578,7 +578,7 @@ module('integration/references/belongs-to', function (hooks) { }); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -590,7 +590,7 @@ module('integration/references/belongs-to', function (hooks) { }, }); - let familyReference = person.belongsTo('family'); + const familyReference = person.belongsTo('family'); await familyReference.reload({ adapterOptions }).then(function (record) { assert.strictEqual(get(record, 'name'), 'Coreleone'); diff --git a/tests/main/tests/integration/references/has-many-test.js b/tests/main/tests/integration/references/has-many-test.js index 848109e3c15..76127007a1c 100755 --- a/tests/main/tests/integration/references/has-many-test.js +++ b/tests/main/tests/integration/references/has-many-test.js @@ -36,7 +36,7 @@ module('integration/references/has-many', function (hooks) { }); testInDebug("record#hasMany asserts when specified relationship doesn't exist", function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const family = store.push({ data: { @@ -53,7 +53,7 @@ module('integration/references/has-many', function (hooks) { testInDebug( "record#hasMany asserts when the type of the specified relationship isn't the requested one", function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const person = store.push({ data: { @@ -69,7 +69,7 @@ module('integration/references/has-many', function (hooks) { ); test('record#hasMany', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const family = store.push({ data: { @@ -94,7 +94,7 @@ module('integration/references/has-many', function (hooks) { }); test('record#hasMany for linked references', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const family = store.push({ data: { @@ -116,7 +116,7 @@ module('integration/references/has-many', function (hooks) { }); test('HasManyReference#meta() returns the most recent meta for the relationship', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const family = store.push({ data: { @@ -138,17 +138,17 @@ module('integration/references/has-many', function (hooks) { }); test('HasManyReference#value() does not create accidental autotracking errors', async function (assert) { - let store = this.owner.lookup('service:store'); - let family = store.push({ + const store = this.owner.lookup('service:store'); + const family = store.push({ data: { type: 'family', id: '1', }, }); - let personsReference = family.hasMany('persons'); + const personsReference = family.hasMany('persons'); let renderedValue; - let context = await createTrackingContext(this.owner, { + const context = await createTrackingContext(this.owner, { get value() { renderedValue = personsReference.value(); return renderedValue; @@ -175,7 +175,7 @@ module('integration/references/has-many', function (hooks) { assert.strictEqual(renderedValue, null, 'We have no value yet, we are still not loaded'); - let person1 = store.push({ + const person1 = store.push({ data: { type: 'person', id: '1', @@ -226,7 +226,7 @@ module('integration/references/has-many', function (hooks) { await context.render(); - let person2 = store.peekRecord('person', '2'); + const person2 = store.peekRecord('person', '2'); assert.notStrictEqual(person2, null, 'we have a person'); assert.strictEqual(renderedValue.length, 2, 'We have two values'); assert.strictEqual(renderedValue.at(0), person1, 'We have the right value[0]'); @@ -275,7 +275,7 @@ module('integration/references/has-many', function (hooks) { @belongsTo('family', { async: true, inverse: 'persons', as: 'person' }) family; } - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); this.owner.register('model:family', Family); this.owner.register('model:person', Person); @@ -323,7 +323,7 @@ module('integration/references/has-many', function (hooks) { }); testInDebug('push(object) supports legacy, non-JSON-API-conform payload', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var family = store.push({ data: { @@ -389,7 +389,7 @@ module('integration/references/has-many', function (hooks) { }); test('value() returns null when reference is not yet loaded', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var family = store.push({ data: { @@ -411,7 +411,7 @@ module('integration/references/has-many', function (hooks) { }); test('value() returns the referenced records when all records are loaded', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var family = store.push({ data: { @@ -437,7 +437,7 @@ module('integration/references/has-many', function (hooks) { }); test('value() returns an empty array when the reference is loaded and empty', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var family = store.push({ data: { @@ -457,7 +457,7 @@ module('integration/references/has-many', function (hooks) { }); test('_isLoaded() returns an true array when the reference is loaded and empty', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var family = store.push({ data: { @@ -477,8 +477,8 @@ module('integration/references/has-many', function (hooks) { }); test('load() fetches the referenced records', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -516,8 +516,8 @@ module('integration/references/has-many', function (hooks) { }); test('load() fetches link when remoteType is link', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -555,8 +555,8 @@ module('integration/references/has-many', function (hooks) { }); test('load() fetches link when remoteType is link but an empty set of records is returned', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -567,7 +567,7 @@ module('integration/references/has-many', function (hooks) { return Promise.resolve({ data: [] }); }; - let family = store.push({ + const family = store.push({ data: { type: 'family', id: '1', @@ -579,7 +579,7 @@ module('integration/references/has-many', function (hooks) { }, }); - let personsReference = family.hasMany('persons'); + const personsReference = family.hasMany('persons'); assert.strictEqual(personsReference.remoteType(), 'link'); await personsReference.load({ adapterOptions }).then((records) => { @@ -589,10 +589,10 @@ module('integration/references/has-many', function (hooks) { }); test('load() - only a single find is triggered', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let resolveRequest; - let defered = new Promise((resolve) => { + const defered = new Promise((resolve) => { resolveRequest = resolve; }); let count = 0; @@ -640,8 +640,8 @@ module('integration/references/has-many', function (hooks) { }); test('reload()', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -681,8 +681,8 @@ module('integration/references/has-many', function (hooks) { }); test('reload() fetches link when remoteType is link', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const adapterOptions = { thing: 'one' }; @@ -738,9 +738,9 @@ module('integration/references/has-many', function (hooks) { test('push record with nested includes (async has-many), chained HasManyReference#value()', async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let family = store.push({ + const family = store.push({ data: { type: 'family', id: '1', @@ -821,10 +821,10 @@ module('integration/references/has-many', function (hooks) { ], }); - let persons = family.hasMany('persons').value(); + const persons = family.hasMany('persons').value(); assert.strictEqual(persons.length, 2); persons.forEach((person) => { - let pets = person.hasMany('pets').value(); + const pets = person.hasMany('pets').value(); assert.strictEqual(pets.length, 2); }); }); @@ -832,8 +832,8 @@ module('integration/references/has-many', function (hooks) { test('fetch record with nested includes (async has-many), chained HasManyReference#value', async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshots) { return Promise.resolve({ @@ -918,11 +918,11 @@ module('integration/references/has-many', function (hooks) { }); }; - let family = await store.findRecord('family', '1'); - let persons = family.hasMany('persons').value(); + const family = await store.findRecord('family', '1'); + const persons = family.hasMany('persons').value(); assert.strictEqual(persons.length, 2); persons.forEach((person) => { - let pets = person.hasMany('pets').value(); + const pets = person.hasMany('pets').value(); assert.strictEqual(pets.length, 2); }); }); diff --git a/tests/main/tests/integration/references/record-test.js b/tests/main/tests/integration/references/record-test.js index ef5774a41f9..81656955983 100644 --- a/tests/main/tests/integration/references/record-test.js +++ b/tests/main/tests/integration/references/record-test.js @@ -24,8 +24,8 @@ module('integration/references/record', function (hooks) { }); test('a RecordReference can be retrieved via store.getReference(type, id)', function (assert) { - let store = this.owner.lookup('service:store'); - let recordReference = store.getReference('person', 1); + const store = this.owner.lookup('service:store'); + const recordReference = store.getReference('person', 1); assert.strictEqual(recordReference.remoteType(), 'identity'); assert.strictEqual(recordReference.type, 'person'); @@ -33,8 +33,8 @@ module('integration/references/record', function (hooks) { }); test('a RecordReference can be retrieved via store.getReference(identifier) without local state', function (assert) { - let store = this.owner.lookup('service:store'); - let recordReference = store.getReference({ type: 'person', id: '1' }); + const store = this.owner.lookup('service:store'); + const recordReference = store.getReference({ type: 'person', id: '1' }); assert.strictEqual(recordReference.remoteType(), 'identity'); assert.strictEqual(recordReference.type, 'person'); @@ -71,7 +71,7 @@ module('integration/references/record', function (hooks) { } } - let recordReference = store.getReference(getReferenceArgs); + const recordReference = store.getReference(getReferenceArgs); assert.strictEqual(recordReference.remoteType(), 'identity'); assert.strictEqual(recordReference.type, 'person'); @@ -84,10 +84,10 @@ module('integration/references/record', function (hooks) { }); test('push(object)', async function (assert) { - let store = this.owner.lookup('service:store'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const Person = store.modelFor('person'); - let recordReference = store.getReference('person', 1); + const recordReference = store.getReference('person', 1); const pushed = recordReference.push({ data: { @@ -101,19 +101,19 @@ module('integration/references/record', function (hooks) { assert.ok(pushed.then, 'RecordReference.push returns a promise'); - let record = await pushed; + const record = await pushed; assert.ok(record instanceof Person, 'push resolves with the record'); assert.strictEqual(get(record, 'name'), 'le name'); }); test('push(promise)', async function (assert) { - let store = this.owner.lookup('service:store'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const Person = store.modelFor('person'); - let deferred = createDeferred(); - let recordReference = store.getReference('person', 1); + const deferred = createDeferred(); + const recordReference = store.getReference('person', 1); - let pushed = recordReference.push(deferred.promise); + const pushed = recordReference.push(deferred.promise); assert.ok(pushed.then, 'RecordReference.push returns a promise'); @@ -127,34 +127,34 @@ module('integration/references/record', function (hooks) { }, }); - let record = await pushed; + const record = await pushed; assert.ok(record instanceof Person, 'push resolves with the record'); assert.strictEqual(get(record, 'name'), 'le name', 'name is updated'); }); test('value() returns null when not yet loaded', function (assert) { - let store = this.owner.lookup('service:store'); - let recordReference = store.getReference('person', 1); + const store = this.owner.lookup('service:store'); + const recordReference = store.getReference('person', 1); assert.strictEqual(recordReference.value(), null); }); test('value() returns the record when loaded', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', }, }); - let recordReference = store.getReference('person', 1); + const recordReference = store.getReference('person', 1); assert.strictEqual(recordReference.value(), person); }); test('load() fetches the record', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { return Promise.resolve({ @@ -168,22 +168,22 @@ module('integration/references/record', function (hooks) { }); }; - let recordReference = store.getReference('person', 1); + const recordReference = store.getReference('person', 1); - let record = await recordReference.load(); + const record = await recordReference.load(); assert.strictEqual(get(record, 'name'), 'Vito'); }); test('load() only a single find is triggered', async function (assert) { assert.expect(3); let resolveRequest; - let deferred = new Promise((resolve) => { + const deferred = new Promise((resolve) => { resolveRequest = resolve; }); let count = 0; - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldReloadRecord = function () { return false; @@ -198,10 +198,10 @@ module('integration/references/record', function (hooks) { return deferred; }; - let recordReference = store.getReference('person', 1); + const recordReference = store.getReference('person', 1); recordReference.load(); // first trigger - let recordPromise = recordReference.load(); // second trigger + const recordPromise = recordReference.load(); // second trigger resolveRequest({ data: { id: '1', @@ -219,8 +219,8 @@ module('integration/references/record', function (hooks) { }); test('reload() loads the record if not yet loaded', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let count = 0; adapter.findRecord = function (store, type, id) { @@ -238,15 +238,15 @@ module('integration/references/record', function (hooks) { }); }; - let recordReference = store.getReference('person', 1); + const recordReference = store.getReference('person', 1); - let record = await recordReference.reload(); + const record = await recordReference.reload(); assert.strictEqual(get(record, 'name'), 'Vito Coreleone'); }); test('reload() fetches the record', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { return Promise.resolve({ @@ -270,9 +270,9 @@ module('integration/references/record', function (hooks) { }, }); - let recordReference = store.getReference('person', 1); + const recordReference = store.getReference('person', 1); - let record = await recordReference.reload(); + const record = await recordReference.reload(); assert.strictEqual(get(record, 'name'), 'Vito Coreleone'); }); }); diff --git a/tests/main/tests/integration/relationships/belongs-to-test.js b/tests/main/tests/integration/relationships/belongs-to-test.js index f91246eca39..9cff6138e4e 100644 --- a/tests/main/tests/integration/relationships/belongs-to-test.js +++ b/tests/main/tests/integration/relationships/belongs-to-test.js @@ -30,7 +30,7 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' } hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('model:pet', Pet); owner.register( @@ -127,7 +127,7 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' }) ); - let company = store.createRecord('company', { name: 'Acme Corporation' }); + const company = store.createRecord('company', { name: 'Acme Corporation' }); await company.save(); assert.strictEqual(company.id, '123', 'We updated to the correct id'); assert.strictEqual(company.belongsTo('parentCompany').id(), company.id, 'We are able to reference ourselves'); @@ -186,17 +186,17 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' }) ); - let person = await store.findRecord('person', '1'); - let petRequest = store.findRecord('pet', '1'); - let personPetRequest = person.bestDog; - let personPet = await personPetRequest; - let pet = await petRequest; + const person = await store.findRecord('person', '1'); + const petRequest = store.findRecord('pet', '1'); + const personPetRequest = person.bestDog; + const personPet = await personPetRequest; + const pet = await petRequest; assert.strictEqual(personPet, pet, 'We ended up in the same state'); }); test('async belongsTo returns correct new value after a local change', async function (assert) { - let chris = store.push({ + const chris = store.push({ data: { type: 'person', id: '1', @@ -231,8 +231,8 @@ module('integration/relationship/belongs-to BelongsTo Relationships (new-style)' ], }); - let shen = store.peekRecord('pet', '1'); - let pirate = store.peekRecord('pet', '2'); + const shen = store.peekRecord('pet', '1'); + const pirate = store.peekRecord('pet', '2'); let bestDog = await chris.bestDog; assert.strictEqual(shen.bestHuman, null, 'precond - Shen has no best human'); @@ -393,8 +393,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }) ); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.push({ data: { @@ -477,8 +477,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:post', Post); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = function (store, type, id, snapshot) { @@ -514,11 +514,11 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function testInDebug('Invalid belongsTo relationship identifiers throw errors for null id', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // test null id assert.expectAssertion(() => { - let post = store.push({ + const post = store.push({ data: { id: '1', type: 'post', @@ -539,11 +539,11 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function testInDebug('Invalid belongsTo relationship identifiers throw errors for null type', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // test missing type assert.expectAssertion(() => { - let post = store.push({ + const post = store.push({ data: { id: '2', type: 'post', @@ -565,7 +565,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function 'Only a record of the same modelClass can be used with a monomorphic belongsTo relationship', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const post = store.push({ data: { @@ -587,8 +587,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function ); test('The store can load a polymorphic belongsTo association', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -620,12 +620,12 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test('The store can serialize a polymorphic belongsTo association', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; - let serializerInstance = store.serializerFor('comment'); + const serializerInstance = store.serializerFor('comment'); serializerInstance.serializePolymorphicType = function (record, json, relationship) { assert.ok(true, "The serializer's serializePolymorphicType method should be called"); @@ -655,23 +655,23 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); await store.findRecord('comment', '2').then((comment) => { - let serialized = comment.serialize({ includeId: true }); + const serialized = comment.serialize({ includeId: true }); assert.strictEqual(serialized.data.relationships.message.data.id, '1'); assert.strictEqual(serialized.data.relationships.message.data.type, 'posts'); }); }); test('A serializer can materialize a belongsTo as a link that gets sent back to findBelongsTo', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; - let Group = Model.extend({ + const Group = Model.extend({ people: hasMany('person', { async: false, inverse: 'group' }), }); - let Person = Model.extend({ + const Person = Model.extend({ group: belongsTo('group', { async: true, inverse: 'people' }), }); @@ -726,16 +726,16 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test('A record with an async belongsTo relationship always returns a promise for that relationship', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; - let Seat = Model.extend({ + const Seat = Model.extend({ person: belongsTo('person', { async: false, inverse: 'seat' }), }); - let Person = Model.extend({ + const Person = Model.extend({ seat: belongsTo('seat', { async: true, inverse: 'person' }), }); @@ -777,16 +777,16 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function test('A record with an async belongsTo relationship returning null should resolve null', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; - let Group = Model.extend({ + const Group = Model.extend({ people: hasMany('person', { async: false, inverse: 'group' }), }); - let Person = Model.extend({ + const Person = Model.extend({ group: belongsTo('group', { async: true, inverse: 'people' }), }); @@ -828,10 +828,10 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function test('polymorphic belongsTo class-checks check the superclass', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let igor = store.createRecord('user', { name: 'Igor' }); - let post = store.createRecord('post', { title: "Igor's unimaginative blog post" }); + const igor = store.createRecord('user', { name: 'Igor' }); + const post = store.createRecord('post', { title: "Igor's unimaginative blog post" }); igor.set('favouriteMessage', post); @@ -854,8 +854,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function * - comment is destroyed */ - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Message extends Model { @attr('date') created_at; @@ -936,8 +936,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function test('Destroying a record with an unloaded aync belongsTo association does not fetch the record', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); class Post extends Model { @attr('string') title; @@ -994,9 +994,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); testInDebug('A sync belongsTo errors out if the record is unloaded', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let message = store.push({ + const message = store.push({ data: { id: '1', type: 'message', @@ -1024,9 +1024,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let book, author; - book = store.push({ + const store = this.owner.lookup('service:store'); + const book = store.push({ data: { id: '1', type: 'book', @@ -1043,7 +1042,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }, }, }); - author = store.push({ + const author = store.push({ data: { id: '2', type: 'author', @@ -1062,10 +1061,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test('Rollbacking attributes for a deleted record restores implicit relationship - sync', function (assert) { - let store = this.owner.lookup('service:store'); - let book, author; + const store = this.owner.lookup('service:store'); - book = store.push({ + const book = store.push({ data: { id: '1', type: 'book', @@ -1083,7 +1081,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }, }); - author = store.push({ + const author = store.push({ data: { id: '2', type: 'author', @@ -1107,8 +1105,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function @hasMany('chapter', { async: false, inverse: 'book' }) chapters; } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -1124,7 +1122,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }; await store.findRecord('book', 1).then((book) => { - let relationship = getRelationshipStateForRecord(book, 'author'); + const relationship = getRelationshipStateForRecord(book, 'author'); assert.true(relationship.state.hasReceivedData, 'relationship has data'); }); }); @@ -1132,8 +1130,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function test('belongsTo hasAnyRelationshipData sync loaded', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -1149,7 +1147,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }; await store.findRecord('book', 1).then((book) => { - let relationship = getRelationshipStateForRecord(book, 'author'); + const relationship = getRelationshipStateForRecord(book, 'author'); assert.true(relationship.state.hasReceivedData, 'relationship has data'); }); }); @@ -1162,8 +1160,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function @hasMany('chapter', { async: false, inverse: 'book' }) chapters; } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -1179,7 +1177,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }; await store.findRecord('book', 1).then((book) => { - let relationship = getRelationshipStateForRecord(book, 'author'); + const relationship = getRelationshipStateForRecord(book, 'author'); assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); }); }); @@ -1187,8 +1185,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function test('belongsTo hasAnyRelationshipData sync not loaded', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -1201,7 +1199,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }; await store.findRecord('book', 1).then((book) => { - let relationship = getRelationshipStateForRecord(book, 'author'); + const relationship = getRelationshipStateForRecord(book, 'author'); assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); }); }); @@ -1214,9 +1212,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function @hasMany('chapter', { async: false, inverse: 'book' }) chapters; } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let author = store.createRecord('author'); + const author = store.createRecord('author'); let book = store.createRecord('book', { name: 'The Greatest Book' }); let relationship = getRelationshipStateForRecord(book, 'author'); @@ -1235,9 +1233,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function test('belongsTo hasAnyRelationshipData sync created', function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let author = store.createRecord('author'); + const author = store.createRecord('author'); let book = store.createRecord('book', { name: 'The Greatest Book', }); @@ -1255,10 +1253,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test("Model's belongsTo relationship should not be created during model creation", function (assert) { - let store = this.owner.lookup('service:store'); - let user; + const store = this.owner.lookup('service:store'); - user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -1272,9 +1269,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test("Model's belongsTo relationship should be created during model creation if relationship passed in constructor", function (assert) { - let store = this.owner.lookup('service:store'); - let message = store.createRecord('message'); - let user = store.createRecord('user', { + const store = this.owner.lookup('service:store'); + const message = store.createRecord('message'); + const user = store.createRecord('user', { name: 'John Doe', favouriteMessage: message, }); @@ -1286,11 +1283,10 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test("Model's belongsTo relationship should be created during 'set' method", function (assert) { - let store = this.owner.lookup('service:store'); - let user, message; + const store = this.owner.lookup('service:store'); - message = store.createRecord('message'); - user = store.createRecord('user'); + const message = store.createRecord('message'); + const user = store.createRecord('user'); user.set('favouriteMessage', message); assert.ok( hasRelationshipForRecord(user, 'favouriteMessage'), @@ -1299,10 +1295,9 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test("Model's belongsTo relationship should be created during 'get' method", function (assert) { - let store = this.owner.lookup('service:store'); - let user; + const store = this.owner.lookup('service:store'); - user = store.createRecord('user'); + const user = store.createRecord('user'); user.favouriteMessage; assert.ok( hasRelationshipForRecord(user, 'favouriteMessage'), @@ -1319,8 +1314,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'author', 'url is correct'); @@ -1334,7 +1329,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); }; - let book = store.push({ + const book = store.push({ data: { type: 'book', id: '1', @@ -1363,8 +1358,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.ok(true, "The adapter's findBelongsTo method should be called"); @@ -1381,7 +1376,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.ok(false, "The adapter's findRecord method should not be called"); }; - let book = store.push({ + const book = store.push({ data: { type: 'book', id: '1', @@ -1411,8 +1406,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => { return false; @@ -1425,7 +1420,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.ok(false, "The adapter's findRecord method should not be called"); }; - let book = store.push({ + const book = store.push({ data: { type: 'book', id: '1', @@ -1462,8 +1457,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'author-new-link', 'url is correct'); @@ -1481,7 +1476,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.ok(false, "The adapter's findRecord method should not be called"); }; - let book = store.push({ + const book = store.push({ data: { type: 'book', id: '1', @@ -1525,8 +1520,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findBelongsTo = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'author-updated-link', 'url is correct'); @@ -1546,7 +1541,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.ok(false, "The adapter's findRecord method should not be called"); }; - let book = store.push({ + const book = store.push({ data: { type: 'book', id: '1', @@ -1605,8 +1600,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:book', Book); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findBelongsTo = function () { assert.ok(false, "The adapter's findBelongsTo method should not be called"); @@ -1616,7 +1611,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function assert.ok(false, "The adapter's findRecord method should not be called"); }; - let book = store.push({ + const book = store.push({ data: { type: 'book', id: '1', @@ -1672,8 +1667,8 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:chapter', Chapter); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function () { return Promise.resolve({ @@ -1729,10 +1724,10 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); test('A synchronous belongsTo relationship can be reloaded using a reference if it was fetched via id', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let chapter = store.push({ + const chapter = store.push({ data: { type: 'chapter', id: '1', @@ -1763,7 +1758,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); }; - let book = chapter.book; + const book = chapter.book; assert.strictEqual(book.name, 'book title'); await chapter @@ -1781,10 +1776,10 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:chapter', Chapter); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let chapter = store.push({ + const chapter = store.push({ data: { type: 'chapter', id: '1', @@ -1828,10 +1823,10 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function }); testInDebug('A belongsTo relationship warns if malformatted data is pushed into the store', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async () => { - let chapter = store.push({ + const chapter = store.push({ data: { type: 'chapter', id: '1', @@ -1853,7 +1848,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function } this.owner.register('model:chapter', Chapter); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -1869,7 +1864,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function included: [{ type: 'book', id: '1' }], }); - let chapter = store.peekRecord('chapter', '1'); + const chapter = store.peekRecord('chapter', '1'); let count = 0; chapter.addObserver('book', () => { @@ -1929,7 +1924,6 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function const friend = await bestFriendPromise; const enemy = await worstEnemyPromise; - // eslint-disable-next-line qunit/no-ok-equality assert.true(friend !== enemy, 'we got separate records'); }); }); diff --git a/tests/main/tests/integration/relationships/has-many-test.js b/tests/main/tests/integration/relationships/has-many-test.js index d1115eeacf6..2f66aa4544c 100644 --- a/tests/main/tests/integration/relationships/has-many-test.js +++ b/tests/main/tests/integration/relationships/has-many-test.js @@ -149,11 +149,11 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( testInDebug('Invalid hasMany relationship identifiers throw errors for missing id', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // test null id assert.expectAssertion(() => { - let post = store.push({ + const post = store.push({ data: { id: '1', type: 'post', @@ -172,11 +172,11 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( testInDebug('Invalid hasMany relationship identifiers throw errors for missing type', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // test missing type assert.expectAssertion(() => { - let post = store.push({ + const post = store.push({ data: { id: '2', type: 'post', @@ -252,10 +252,10 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( test("When a hasMany relationship is accessed, the adapter's findMany method should not be called if all the records in the relationship are already loaded", async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let postData = { + const postData = { type: 'post', id: '1', relationships: { @@ -297,9 +297,9 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( test('hasMany + canonical vs currentState + destroyRecord ', async function (assert) { assert.expect(7); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let postData = { + const postData = { type: 'user', id: '1', attributes: { @@ -325,7 +325,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }, }; - let user = store.push({ + const user = store.push({ data: postData, included: [ { @@ -347,7 +347,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( return { data: { type: 'user', id: '2' } }; }; - let contacts = user.contacts; + const contacts = user.contacts; assert.deepEqual( contacts.map((c) => c.id), ['2', '3', '4'], @@ -389,9 +389,9 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( test('hasMany + canonical vs currentState + unloadRecord', function (assert) { assert.expect(6); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let postData = { + const postData = { type: 'user', id: '1', attributes: { @@ -417,7 +417,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }, }; - let user = store.push({ + const user = store.push({ data: postData, included: [ { @@ -434,7 +434,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }, ], }); - let contacts = user.contacts; + const contacts = user.contacts; store.adapterFor('user').deleteRecord = function () { return { data: { type: 'user', id: '2' } }; @@ -485,11 +485,11 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let Chapter = store.modelFor('chapter'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const Chapter = store.modelFor('chapter'); - let bookData = { + const bookData = { type: 'book', id: '1', relationships: { @@ -552,8 +552,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); // When the store asks the adapter for the record with ID 1, // provide some fake data. @@ -619,10 +619,10 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -642,7 +642,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual(count, 1, 'findHasMany has only been called once'); return new Promise((resolve, reject) => { setTimeout(() => { - let value = { + const value = { data: [ { id: '1', type: 'comment', attributes: { body: 'First' } }, { id: '2', type: 'comment', attributes: { body: 'Second' } }, @@ -653,9 +653,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - let promise1, promise2; - - promise1 = post.comments; + const promise1 = post.comments; //Invalidate the post.comments CP store.push({ data: { @@ -668,7 +666,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }, }, }); - promise2 = post.comments; + const promise2 = post.comments; await Promise.all([promise1, promise2]); assert.strictEqual(promise1.promise, promise2.promise, 'Same promise is returned both times'); @@ -689,8 +687,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, link, relationship) { return Promise.resolve({ @@ -701,7 +699,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -746,8 +744,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( } this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, link, relationship) { return Promise.resolve({ data: [] }); @@ -767,7 +765,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - let post = store.createRecord('post', {}); + const post = store.createRecord('post', {}); store.createRecord('comment', { message: post }); await post.comments @@ -795,8 +793,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, link, relationship) { return Promise.resolve({ @@ -818,7 +816,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - let post = store.createRecord('post', {}); + const post = store.createRecord('post', {}); store.createRecord('comment', { message: post }); await post.comments @@ -845,18 +843,18 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function (store, snapshot, link, relationship) { return Promise.resolve({ data: { id: '1', type: 'post' } }); }; - let post = store.createRecord('post', {}); + const post = store.createRecord('post', {}); // create a new comment with id 'local', which is in the 'comments' // relationship of post - let localComment = store.createRecord('comment', { id: 'local', message: post }); + const localComment = store.createRecord('comment', { id: 'local', message: post }); await post.comments .then((comments) => { @@ -910,8 +908,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(type, Post, 'find type was Post'); @@ -943,8 +941,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); }; - let post = await store.findRecord('post', 1); - let comments = await post.comments; + const post = await store.findRecord('post', 1); + const comments = await post.comments; assert.true(comments.isLoaded, 'comments are loaded'); assert.strictEqual(comments.length, 2, 'comments have 2 length'); @@ -968,8 +966,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); test('A sync hasMany relationship can be reloaded if it was fetched via ids', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(type, store.modelFor('post'), 'find type was Post'); @@ -1013,7 +1011,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( await store .findRecord('post', '1') .then(function (post) { - let comments = post.comments; + const comments = post.comments; assert.true(comments.isLoaded, 'comments are loaded'); assert.strictEqual(comments.length, 2, 'comments have a length of 2'); @@ -1047,8 +1045,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(type, Post, 'find type was Post'); @@ -1118,8 +1116,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function () { return Promise.resolve({ @@ -1150,8 +1148,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( } }; - let post = await store.findRecord('post', '1'); - let commentsPromiseArray = post.comments; + const post = await store.findRecord('post', '1'); + const commentsPromiseArray = post.comments; let manyArray; try { @@ -1173,7 +1171,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.true(manyArray.isLoaded, 'the second reload failed, comments are still loaded though'); - let reloadedManyArray = await manyArray.reload(); + const reloadedManyArray = await manyArray.reload(); assert.true(reloadedManyArray.isLoaded, 'the third reload worked, comments are loaded again'); assert.strictEqual(reloadedManyArray, manyArray, 'the many array stays the same'); @@ -1194,8 +1192,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { assert.strictEqual(type, Post, 'find type was Post'); @@ -1247,10 +1245,10 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let done = assert.async(); + const done = assert.async(); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { return Promise.resolve({ @@ -1282,7 +1280,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual( count, 2, - 'One request for the original access and only one request for the mulitple reloads' + 'One request for the original access and only one request for the multiple reloads' ); done(); }); @@ -1303,8 +1301,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(type, Post, 'find type was Post'); @@ -1358,10 +1356,10 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let done = assert.async(); + const done = assert.async(); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -1397,7 +1395,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( assert.strictEqual( count, 2, - 'One request for the original access and only one request for the mulitple reloads' + 'One request for the original access and only one request for the multiple reloads' ); done(); }); @@ -1419,8 +1417,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, link, relationship) { assert.strictEqual(relationship.type, 'comment', 'relationship was passed correctly'); @@ -1442,7 +1440,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( }); } }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -1482,8 +1480,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( test("When a polymorphic hasMany relationship is accessed, the adapter's findMany method should not be called if all the records in the relationship are already loaded", async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findMany = function (store, type, ids, snapshots) { assert.ok(false, "The adapter's find method should not be called"); @@ -1535,8 +1533,8 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( } this.owner.register('model:user', User); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = function (store, type, id, snapshot) { @@ -1575,10 +1573,10 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( test('polymorphic hasMany type-checks check the superclass', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let igor = store.createRecord('user', { name: 'Igor' }); - let comment = store.createRecord('comment', { + const igor = store.createRecord('user', { name: 'Igor' }); + const comment = store.createRecord('comment', { body: 'Well I thought the title was fine', }); @@ -1650,10 +1648,10 @@ module('integration/relationships/has_many - Has-Many Relationships', function ( this.owner.register('model:phone', Phone); this.owner.register('model:post', Post); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let email = store.createRecord('email'); - let post = store.createRecord('post', { + const email = store.createRecord('email'); + const post = store.createRecord('post', { contact: email, }); @@ -2093,8 +2091,8 @@ If using this relationship in a polymorphic manner is desired, the relationships test('A record can be removed from a polymorphic association', async function (assert) { assert.expect(4); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -2121,7 +2119,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.strictEqual(messages.length, 1, 'The user has 1 message'); - let removedObject = messages.pop(); + const removedObject = messages.pop(); assert.strictEqual(removedObject, comment, 'The message is correctly removed'); assert.strictEqual(messages.length, 0, 'The user does not have any messages'); @@ -2131,11 +2129,11 @@ If using this relationship in a polymorphic manner is desired, the relationships test('When a record is created on the client, its hasMany arrays should be in a loaded state', async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post'); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post'); assert.ok(post.isLoaded, 'The post should have isLoaded flag'); - let comments = post.comments; + const comments = post.comments; await comments; assert.strictEqual(comments.length, 0, 'The comments should be an empty array'); @@ -2157,8 +2155,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post'); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post'); assert.ok(post.isLoaded, 'The post should have isLoaded flag'); @@ -2171,8 +2169,8 @@ If using this relationship in a polymorphic manner is desired, the relationships test('we can set records SYNC HM relationship', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post'); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post'); store.push({ data: [ @@ -2211,8 +2209,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post'); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post'); store.push({ data: [ @@ -2242,16 +2240,15 @@ If using this relationship in a polymorphic manner is desired, the relationships test('When a record is saved, its unsaved hasMany records should be kept', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function (store, type, snapshot) { return Promise.resolve({ data: { id: '1', type: snapshot.modelName } }); }; - let post, comment; - post = store.createRecord('post'); - comment = store.createRecord('comment'); + const post = store.createRecord('post'); + const comment = store.createRecord('comment'); post.comments.push(comment); await post.save(); assert.strictEqual(post.comments.length, 1, "The unsaved comment should be in the post's comments array"); @@ -2270,16 +2267,16 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function (store, type, snapshot) { - let serialized = snapshot.record.serialize(); + const serialized = snapshot.record.serialize(); serialized.data.id = 2; return Promise.resolve(serialized); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -2290,7 +2287,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }, }, }); - let firstComment = store.push({ + const firstComment = store.push({ data: { type: 'comment', id: '1', @@ -2305,9 +2302,9 @@ If using this relationship in a polymorphic manner is desired, the relationships const comment = store.createRecord('comment', { post }); await comment.save(); - let commentPost = comment.post; - let postComments = comment.post.comments; - let postCommentsLength = comment.get('post.comments.length'); + const commentPost = comment.post; + const postComments = comment.post.comments; + const postCommentsLength = comment.get('post.comments.length'); assert.deepEqual(post, commentPost, 'expect the new comments post, to be the correct post'); assert.ok(postComments, 'comments should exist'); @@ -2330,8 +2327,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let findManyCalls = 0; let findRecordCalls = 0; @@ -2352,7 +2349,7 @@ If using this relationship in a polymorphic manner is desired, the relationships return Promise.resolve({ data: { id: '3', type: 'comment', attributes: { body: 'third' } } }); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -2367,7 +2364,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }, }); - let fetchedComments = await post.comments; + const fetchedComments = await post.comments; assert.strictEqual(fetchedComments.length, 2, 'comments fetched successfully'); assert.strictEqual(fetchedComments.at(0).body, 'first', 'first comment loaded successfully'); @@ -2388,16 +2385,16 @@ If using this relationship in a polymorphic manner is desired, the relationships }, }); - let newlyFetchedComments = await post.comments; + const newlyFetchedComments = await post.comments; assert.strictEqual(newlyFetchedComments.length, 3, 'all three comments fetched successfully'); assert.strictEqual(newlyFetchedComments.at(2).body, 'third', 'third comment loaded successfully'); }); testInDebug('A sync hasMany errors out if there are unloaded records in it', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -2424,8 +2421,8 @@ If using this relationship in a polymorphic manner is desired, the relationships }); testInDebug('An async hasMany does not fetch with a model created with no options', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function () { assert.ok(false, 'no request should be made'); }; @@ -2446,8 +2443,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let comment = store.createRecord('comment'); - let post = store.push({ + const comment = store.createRecord('comment'); + const post = store.push({ data: { type: 'post', id: '1', @@ -2460,7 +2457,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test('After removing and unloading a record, a hasMany relationship should still be valid', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const post = store.push({ data: { @@ -2485,7 +2482,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test('If reordered hasMany data has been pushed to the store, the many array reflects the ordering change - sync', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const [comment1, comment2, comment3, comment4, post] = store.push({ data: [ @@ -2613,8 +2610,8 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test('Rollbacking attributes for deleted record restores implicit relationship correctly when the hasMany side has been deleted - async', async function (assert) { - let store = this.owner.lookup('service:store'); - let book = store.push({ + const store = this.owner.lookup('service:store'); + const book = store.push({ data: { type: 'book', id: '1', @@ -2637,7 +2634,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }, ], }); - let chapter = store.peekRecord('chapter', '2'); + const chapter = store.peekRecord('chapter', '2'); chapter.deleteRecord(); chapter.rollbackAttributes(); @@ -2647,8 +2644,8 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test('Rollbacking attributes for deleted record restores implicit relationship correctly when the hasMany side has been deleted - sync', async function (assert) { - let store = this.owner.lookup('service:store'); - let chapter = store.push({ + const store = this.owner.lookup('service:store'); + const chapter = store.push({ data: { type: 'chapter', id: '1', @@ -2671,7 +2668,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }, ], }); - let page = store.peekRecord('page', '2'); + const page = store.peekRecord('page', '2'); page.deleteRecord(); page.rollbackAttributes(); @@ -2686,9 +2683,7 @@ If using this relationship in a polymorphic manner is desired, the relationships } this.owner.register('model:page', Page); - let store = this.owner.lookup('service:store'); - - let chapter, page; + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -2713,8 +2708,8 @@ If using this relationship in a polymorphic manner is desired, the relationships }, ], }); - chapter = store.peekRecord('chapter', '2'); - page = store.peekRecord('page', '3'); + const chapter = store.peekRecord('chapter', '2'); + const page = store.peekRecord('page', '3'); chapter.deleteRecord(); chapter.rollbackAttributes(); @@ -2724,9 +2719,8 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test('Rollbacking attributes for deleted record restores implicit relationship correctly when the belongsTo side has been deleted - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let chapter, page; store.push({ data: { type: 'chapter', @@ -2750,8 +2744,8 @@ If using this relationship in a polymorphic manner is desired, the relationships }, ], }); - chapter = store.peekRecord('chapter', '2'); - page = store.peekRecord('page', '3'); + const chapter = store.peekRecord('chapter', '2'); + const page = store.peekRecord('page', '3'); chapter.deleteRecord(); chapter.rollbackAttributes(); @@ -2772,7 +2766,7 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const [post] = store.push({ data: [ @@ -2849,9 +2843,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let post; store.push({ data: [ { @@ -2889,7 +2882,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }, ], }); - post = store.peekRecord('post', '2'); + const post = store.peekRecord('post', '2'); // This line triggers the original bug that gets manifested // in teardown for apps, e.g. store.destroy that is caused by @@ -2947,7 +2940,7 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -2981,7 +2974,7 @@ If using this relationship in a polymorphic manner is desired, the relationships const post = await store.findRecord('post', '1'); let commentsPromiseArray = post.comments; - let comments = await commentsPromiseArray; + const comments = await commentsPromiseArray; assert.strictEqual(commentsPromiseArray.length, 3, 'Initial comments count'); // Add comment #4 @@ -3015,8 +3008,8 @@ If using this relationship in a polymorphic manner is desired, the relationships } this.owner.register('model:chapter', Chapter); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -3037,7 +3030,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }; await store.findRecord('chapter', '1').then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); + const relationship = getRelationshipStateForRecord(chapter, 'pages'); assert.true(relationship.state.hasReceivedData, 'relationship has data'); }); }); @@ -3045,8 +3038,8 @@ If using this relationship in a polymorphic manner is desired, the relationships test('hasMany hasAnyRelationshipData sync loaded', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -3067,7 +3060,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }; await store.findRecord('chapter', '1').then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); + const relationship = getRelationshipStateForRecord(chapter, 'pages'); assert.true(relationship.state.hasReceivedData, 'relationship has data'); }); }); @@ -3080,8 +3073,8 @@ If using this relationship in a polymorphic manner is desired, the relationships } this.owner.register('model:chapter', Chapter); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -3099,7 +3092,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }; await store.findRecord('chapter', '1').then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); + const relationship = getRelationshipStateForRecord(chapter, 'pages'); assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); }); }); @@ -3107,8 +3100,8 @@ If using this relationship in a polymorphic manner is desired, the relationships test('hasMany hasAnyRelationshipData sync not loaded', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { return Promise.resolve({ @@ -3121,7 +3114,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }; await store.findRecord('chapter', '1').then((chapter) => { - let relationship = getRelationshipStateForRecord(chapter, 'pages'); + const relationship = getRelationshipStateForRecord(chapter, 'pages'); assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); }); }); @@ -3134,9 +3127,9 @@ If using this relationship in a polymorphic manner is desired, the relationships } this.owner.register('model:chapter', Chapter); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); let chapter = store.createRecord('chapter', { title: 'The Story Begins' }); - let page = store.createRecord('page'); + const page = store.createRecord('page'); let relationship = getRelationshipStateForRecord(chapter, 'pages'); assert.false(relationship.state.hasReceivedData, 'relationship does not have data'); @@ -3153,7 +3146,7 @@ If using this relationship in a polymorphic manner is desired, the relationships test('hasMany hasAnyRelationshipData sync created', function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); let chapter = store.createRecord('chapter', { title: 'The Story Begins' }); let relationship = getRelationshipStateForRecord(chapter, 'pages'); @@ -3169,9 +3162,9 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test("Model's hasMany relationship should not be created during model creation", function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -3181,9 +3174,9 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test("Model's belongsTo relationship should be created during 'get' method", async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user = store.createRecord('user'); + const user = store.createRecord('user'); user.messages; assert.ok( hasRelationshipForRecord(user, 'messages'), @@ -3194,14 +3187,14 @@ If using this relationship in a polymorphic manner is desired, the relationships test('metadata is accessible when pushed as a meta property for a relationship', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function () { return Promise.resolve({}); }; - let book = store.push({ + const book = store.push({ data: { type: 'book', id: '1', @@ -3229,8 +3222,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('serializer:application', RESTSerializer); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function () { return Promise.resolve({ @@ -3259,20 +3252,20 @@ If using this relationship in a polymorphic manner is desired, the relationships }); const chapters = await book.chapters; - let meta = chapters.meta; + const meta = chapters.meta; assert.strictEqual(meta?.foo, 'bar', 'metadata is available'); }); test('metadata should be reset between requests', async function (assert) { this.owner.register('serializer:application', RESTSerializer); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let counter = 0; adapter.findHasMany = function () { - let data = { + const data = { meta: { foo: 'bar', }, @@ -3290,8 +3283,6 @@ If using this relationship in a polymorphic manner is desired, the relationships return Promise.resolve(data); }; - let book1, book2; - store.push({ data: [ { @@ -3324,15 +3315,15 @@ If using this relationship in a polymorphic manner is desired, the relationships }, ], }); - book1 = store.peekRecord('book', '1'); - book2 = store.peekRecord('book', '2'); + const book1 = store.peekRecord('book', '1'); + const book2 = store.peekRecord('book', '2'); await book1.chapters.then((chapters) => { - let meta = chapters.meta; + const meta = chapters.meta; assert.strictEqual(meta.foo, 'bar', 'metadata should available'); return book2.chapters.then((chapters) => { - let meta = chapters.meta; + const meta = chapters.meta; assert.strictEqual(meta, null, 'metadata should not be available'); }); }); @@ -3352,8 +3343,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => { return false; @@ -3381,7 +3372,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -3414,8 +3405,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => { return false; @@ -3443,7 +3434,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -3477,8 +3468,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => { return false; @@ -3494,7 +3485,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.ok(false, "The adapter's findHasMany method should not be called"); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -3537,8 +3528,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => { return false; @@ -3566,7 +3557,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -3616,8 +3607,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, url, relationship) { assert.strictEqual(url, 'comments-updated-link', 'url is correct'); @@ -3631,7 +3622,7 @@ If using this relationship in a polymorphic manner is desired, the relationships assert.ok(false, "The adapter's findRecord method should not be called"); }; - let post = store.push({ + const post = store.push({ data: { type: 'post', id: '1', @@ -3680,7 +3671,7 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:user', User); this.owner.register('model:post', Post); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -3710,9 +3701,9 @@ If using this relationship in a polymorphic manner is desired, the relationships ], }); - let user = store.peekRecord('user', 'user-1'); - let postsPromiseArray = user.posts; - let posts = await postsPromiseArray; + const user = store.peekRecord('user', 'user-1'); + const postsPromiseArray = user.posts; + const posts = await postsPromiseArray; store.adapterFor('post').deleteRecord = function () { // just acknowledge all deletes, but with a noop @@ -3751,7 +3742,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test('unloading and reloading a record with hasMany relationship - #3084', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -3775,7 +3766,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); let user = store.peekRecord('user', 'user-1'); - let message = store.peekRecord('message', 'message-1'); + const message = store.peekRecord('message', 'message-1'); assert.strictEqual(user.messages.at(0).id, 'message-1'); assert.strictEqual(message.user.id, 'user-1'); @@ -3807,10 +3798,8 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test('deleted records should stay deleted', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let user; - let message; + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function (store, type, id) { return null; @@ -3844,8 +3833,8 @@ If using this relationship in a polymorphic manner is desired, the relationships ], }); - user = store.peekRecord('user', 'user-1'); - message = store.peekRecord('message', 'message-1'); + const user = store.peekRecord('user', 'user-1'); + const message = store.peekRecord('message', 'message-1'); assert.strictEqual(user.messages.length, 2); @@ -3875,7 +3864,7 @@ If using this relationship in a polymorphic manner is desired, the relationships }); test("hasMany relationship with links doesn't trigger extra change notifications - #4942", async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -3891,7 +3880,7 @@ If using this relationship in a polymorphic manner is desired, the relationships included: [{ type: 'chapter', id: '1' }], }); - let book = store.peekRecord('book', '1'); + const book = store.peekRecord('book', '1'); let count = 0; book.addObserver('chapters', () => { @@ -3916,8 +3905,8 @@ If using this relationship in a polymorphic manner is desired, the relationships this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); const postID = '1'; diff --git a/tests/main/tests/integration/relationships/inverse-relationship-load-test.js b/tests/main/tests/integration/relationships/inverse-relationship-load-test.js index b7e47f7a3be..c9b518518dd 100644 --- a/tests/main/tests/integration/relationships/inverse-relationship-load-test.js +++ b/tests/main/tests/integration/relationships/inverse-relationship-load-test.js @@ -11,7 +11,7 @@ module('inverse relationship load test', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; store = owner.lookup('service:store'); owner.register( 'serializer:application', @@ -24,7 +24,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-many - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -71,7 +71,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -88,18 +88,18 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty, 'relationship state was set up correctly'); assert.strictEqual(dogs.length, 2, 'hasMany relationship has correct number of records'); - let dog1 = dogs.at(0); - let dogPerson1 = await dog1.pal; + const dog1 = dogs.at(0); + const dogPerson1 = await dog1.pal; assert.strictEqual( dogPerson1.id, '1', 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' ); - let dogPerson2 = await dogs.at(1).pal; + const dogPerson2 = await dogs.at(1).pal; assert.strictEqual( dogPerson2.id, '1', @@ -112,7 +112,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-many (left hand async, right hand sync) - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -159,7 +159,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -176,18 +176,18 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty, 'relationship state was set up correctly'); assert.strictEqual(dogs.length, 2, 'hasMany relationship has correct number of records'); - let dog1 = dogs.at(0); - let dogPerson1 = await dog1.pal; + const dog1 = dogs.at(0); + const dogPerson1 = await dog1.pal; assert.strictEqual( dogPerson1.id, '1', 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' ); - let dogPerson2 = await dogs.at(1).pal; + const dogPerson2 = await dogs.at(1).pal; assert.strictEqual( dogPerson2.id, '1', @@ -200,7 +200,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-many - findHasMany/null inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -251,7 +251,7 @@ module('inverse relationship load test', function (hooks) { owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -268,7 +268,7 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty); assert.strictEqual(dogs.length, 2); assert.deepEqual( @@ -276,14 +276,14 @@ module('inverse relationship load test', function (hooks) { ['1', '2'] ); - let dog1 = dogs.at(0); + const dog1 = dogs.at(0); await dog1.destroyRecord(); assert.strictEqual(dogs.length, 1); assert.strictEqual(dogs.at(0).id, '2'); }); test('one-to-one - findBelongsTo/explicit inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -323,7 +323,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -343,7 +343,7 @@ module('inverse relationship load test', function (hooks) { let favoriteDog = await person.favoriteDog; assert.false(person.belongsTo('favoriteDog').belongsToRelationship.state.isEmpty); assert.strictEqual(favoriteDog.id, '1', 'favoriteDog id is set correctly'); - let favoriteDogPerson = await favoriteDog.pal; + const favoriteDogPerson = await favoriteDog.pal; assert.strictEqual( favoriteDogPerson.id, '1', @@ -355,7 +355,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-one (left hand async, right hand sync) - findBelongsTo/explicit inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -395,7 +395,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -415,7 +415,7 @@ module('inverse relationship load test', function (hooks) { let favoriteDog = await person.favoriteDog; assert.false(person.belongsTo('favoriteDog').belongsToRelationship.state.isEmpty); assert.strictEqual(favoriteDog.id, '1', 'favoriteDog id is set correctly'); - let favoriteDogPerson = await favoriteDog.pal; + const favoriteDogPerson = await favoriteDog.pal; assert.strictEqual( favoriteDogPerson.id, '1', @@ -427,7 +427,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-one - findBelongsTo/null inverse - ensures inverse relationship is set up when payload does not return parent relationship info', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -465,7 +465,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -491,7 +491,7 @@ module('inverse relationship load test', function (hooks) { }); test('many-to-many - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -538,7 +538,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -555,16 +555,16 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty); assert.strictEqual(dogs.length, 2, 'left hand side relationship is set up with correct number of records'); - let [dog1, dog2] = dogs.slice(); - let dog1Pals = await dog1.pals; + const [dog1, dog2] = dogs.slice(); + const dog1Pals = await dog1.pals; assert.strictEqual(dog1Pals.length, 1, 'dog1.pals inverse relationship includes correct number of records'); assert.strictEqual(dog1Pals.at(0).id, '1', 'dog1.pals inverse relationship is set up correctly'); - let dog2Pals = await dog2.pals; + const dog2Pals = await dog2.pals; assert.strictEqual(dog2Pals.length, 1, 'dog2.pals inverse relationship includes correct number of records'); assert.strictEqual(dog2Pals.at(0).id, '1', 'dog2.pals inverse relationship is set up correctly'); @@ -574,7 +574,7 @@ module('inverse relationship load test', function (hooks) { }); test('many-to-many (left hand async, right hand sync) - findHasMany/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -621,7 +621,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -638,16 +638,16 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty); assert.strictEqual(dogs.length, 2, 'left hand side relationship is set up with correct number of records'); - let [dog1, dog2] = dogs.slice(); - let dog1Pals = await dog1.pals; + const [dog1, dog2] = dogs.slice(); + const dog1Pals = await dog1.pals; assert.strictEqual(dog1Pals.length, 1, 'dog1.pals inverse relationship includes correct number of records'); assert.strictEqual(dog1Pals.at(0).id, '1', 'dog1.pals inverse relationship is set up correctly'); - let dog2Pals = await dog2.pals; + const dog2Pals = await dog2.pals; assert.strictEqual(dog2Pals.length, 1, 'dog2.pals inverse relationship includes correct number of records'); assert.strictEqual(dog2Pals.at(0).id, '1', 'dog2.pals inverse relationship is set up correctly'); @@ -657,7 +657,7 @@ module('inverse relationship load test', function (hooks) { }); test('many-to-one - findBelongsTo/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -712,17 +712,17 @@ module('inverse relationship load test', function (hooks) { }, }); - let person = await dog.pal; + const person = await dog.pal; assert.false( dog.belongsTo('pal').belongsToRelationship.state.isEmpty, 'belongsTo relationship state was populated' ); assert.strictEqual(person.id, '1', 'dog.person relationship is correctly set up'); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.strictEqual(dogs.length, 1, 'person.dogs inverse relationship includes correct number of records'); - let [dog1] = dogs.slice(); + const [dog1] = dogs.slice(); assert.strictEqual(dog1.id, '1', 'dog1.person inverse relationship is set up correctly'); await person.destroyRecord(); @@ -731,7 +731,7 @@ module('inverse relationship load test', function (hooks) { }); test('many-to-one (left hand async, right hand sync) - findBelongsTo/explicit inverse - adds parent relationship information to the payload if it is not included/added by the serializer', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'adapter:application', @@ -786,17 +786,17 @@ module('inverse relationship load test', function (hooks) { }, }); - let person = await dog.pal; + const person = await dog.pal; assert.false( dog.belongsTo('pal').belongsToRelationship.state.isEmpty, 'belongsTo relationship state was populated' ); assert.strictEqual(person.id, '1', 'dog.person relationship is correctly set up'); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.strictEqual(dogs.length, 1, 'person.dogs inverse relationship includes correct number of records'); - let [dog1] = dogs.slice(); + const [dog1] = dogs.slice(); assert.strictEqual(dog1.id, '1', 'dog1.person inverse relationship is set up correctly'); await person.destroyRecord(); @@ -805,7 +805,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-many - ids/non-link/explicit inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function (assert) { - let { owner } = this; + const { owner } = this; const scooby = { id: '1', @@ -854,7 +854,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -878,18 +878,18 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty, 'relationship state was set up correctly'); assert.strictEqual(dogs.length, 2, 'hasMany relationship has correct number of records'); - let dog1 = dogs.at(0); - let dogPerson1 = await dog1.pal; + const dog1 = dogs.at(0); + const dogPerson1 = await dog1.pal; assert.strictEqual( dogPerson1.id, '1', 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' ); - let dogPerson2 = await dogs.at(1).pal; + const dogPerson2 = await dogs.at(1).pal; assert.strictEqual( dogPerson2.id, '1', @@ -902,7 +902,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-many (left hand async, right hand sync) - ids/non-link/explicit inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function (assert) { - let { owner } = this; + const { owner } = this; const scooby = { id: '1', @@ -951,7 +951,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -975,18 +975,18 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty, 'relationship state was set up correctly'); assert.strictEqual(dogs.length, 2, 'hasMany relationship has correct number of records'); - let dog1 = dogs.at(0); - let dogPerson1 = await dog1.pal; + const dog1 = dogs.at(0); + const dogPerson1 = await dog1.pal; assert.strictEqual( dogPerson1.id, '1', 'dog.person inverse relationship is set up correctly when adapter does not include parent relationships in data.relationships' ); - let dogPerson2 = await dogs.at(1).pal; + const dogPerson2 = await dogs.at(1).pal; assert.strictEqual( dogPerson2.id, '1', @@ -999,7 +999,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-many - ids/non-link/null inverse - ids - records loaded through ids/findRecord are linked to the parent if the response from the server does not include relationship information', async function (assert) { - let { owner } = this; + const { owner } = this; const scooby = { id: '1', @@ -1042,7 +1042,7 @@ module('inverse relationship load test', function (hooks) { class Dog extends Model {} owner.register('model:dog', Dog); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -1066,11 +1066,11 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await person.dogs; + const dogs = await person.dogs; assert.false(person.hasMany('dogs').hasManyRelationship.state.isEmpty, 'relationship state was set up correctly'); assert.strictEqual(dogs.length, 2, 'hasMany relationship has correct number of records'); - let dog1 = dogs.at(0); + const dog1 = dogs.at(0); await dog1.destroyRecord(); assert.strictEqual(dogs.length, 1, 'record removed from hasMany relationship after deletion'); @@ -1078,7 +1078,7 @@ module('inverse relationship load test', function (hooks) { }); test('one-to-many - ids/non-link/explicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies another resource as the relationship value in the response', async function (assert) { - let { owner } = this; + const { owner } = this; const scooby = { id: '1', @@ -1143,7 +1143,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let pal = store.push({ + const pal = store.push({ data: { type: 'pal', id: '1', @@ -1167,7 +1167,7 @@ module('inverse relationship load test', function (hooks) { }, }); - let pal2 = store.push({ + const pal2 = store.push({ data: { type: 'pal', id: '2', @@ -1177,33 +1177,33 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await pal.dogs; + const dogs = await pal.dogs; assert.false(pal.hasMany('dogs').hasManyRelationship.state.isEmpty, 'relationship state was set up correctly'); assert.strictEqual(dogs.length, 0, 'hasMany relationship for parent is empty'); - let pal2Dogs = await pal2.dogs; + const pal2Dogs = await pal2.dogs; assert.strictEqual( pal2Dogs.length, 2, 'hasMany relationship on specified record has correct number of associated records' ); - let allDogs = store.peekAll('dogs').slice(); + const allDogs = store.peekAll('dogs').slice(); for (let i = 0; i < allDogs.length; i++) { - let dog = allDogs[i]; - let dogPerson = await dog.pal; + const dog = allDogs[i]; + const dogPerson = await dog.pal; assert.strictEqual(dogPerson.id, pal2.id, 'right hand side has correct belongsTo value'); } - let dog1 = store.peekRecord('dog', '1'); + const dog1 = store.peekRecord('dog', '1'); await dog1.destroyRecord(); assert.strictEqual(pal2Dogs.length, 1, 'record removed from hasMany relationship after deletion'); assert.strictEqual(pal2Dogs.at(0).id, '2', 'hasMany relationship has correct records'); }); test('one-to-many (left hand async, right hand sync) - ids/non-link/explicit inverse - records loaded through ids/findRecord do not get associated with the parent if the server specifies another resource as the relationship value in the response', async function (assert) { - let { owner } = this; + const { owner } = this; const scooby = { id: '1', @@ -1268,7 +1268,7 @@ module('inverse relationship load test', function (hooks) { } owner.register('model:dog', Dog); - let pal = store.push({ + const pal = store.push({ data: { type: 'pal', id: '1', @@ -1292,7 +1292,7 @@ module('inverse relationship load test', function (hooks) { }, }); - let pal2 = store.push({ + const pal2 = store.push({ data: { type: 'pal', id: '2', @@ -1302,33 +1302,33 @@ module('inverse relationship load test', function (hooks) { }, }); - let dogs = await pal.dogs; + const dogs = await pal.dogs; assert.false(pal.hasMany('dogs').hasManyRelationship.state.isEmpty, 'relationship state was set up correctly'); assert.strictEqual(dogs.length, 0, 'hasMany relationship for parent is empty'); - let pal2Dogs = await pal2.dogs; + const pal2Dogs = await pal2.dogs; assert.strictEqual( pal2Dogs.length, 2, 'hasMany relationship on specified record has correct number of associated records' ); - let allDogs = store.peekAll('dogs').slice(); + const allDogs = store.peekAll('dogs').slice(); for (let i = 0; i < allDogs.length; i++) { - let dog = allDogs[i]; - let dogPerson = await dog.pal; + const dog = allDogs[i]; + const dogPerson = await dog.pal; assert.strictEqual(dogPerson.id, pal2.id, 'right hand side has correct belongsTo value'); } - let dog1 = store.peekRecord('dog', '1'); + const dog1 = store.peekRecord('dog', '1'); await dog1.destroyRecord(); assert.strictEqual(pal2Dogs.length, 1, 'record removed from hasMany relationship after deletion'); assert.strictEqual(pal2Dogs.at(0).id, '2', 'hasMany relationship has correct records'); }); test("loading belongsTo doesn't remove inverse relationship for other instances", async function (assert) { - let { owner } = this; + const { owner } = this; const scooby = { id: '1', @@ -1411,8 +1411,8 @@ module('inverse relationship load test', function (hooks) { owner.register('model:dog', Dog); // load em into store - let dog1 = await owner.lookup('service:store').findRecord('dog', '1'); - let dog2 = await owner.lookup('service:store').findRecord('dog', '2'); + const dog1 = await owner.lookup('service:store').findRecord('dog', '1'); + const dog2 = await owner.lookup('service:store').findRecord('dog', '2'); assert.strictEqual(dog1.belongsTo('person').id(), '1'); assert.strictEqual(dog2.belongsTo('person').id(), '1'); diff --git a/tests/main/tests/integration/relationships/json-api-links-test.js b/tests/main/tests/integration/relationships/json-api-links-test.js index 43822d374d8..95bcd08fe1a 100644 --- a/tests/main/tests/integration/relationships/json-api-links-test.js +++ b/tests/main/tests/integration/relationships/json-api-links-test.js @@ -27,7 +27,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); this.owner.register( 'adapter:user', @@ -100,7 +100,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const parent = store.push({ data: { @@ -174,7 +174,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // push data, no links store.push({ @@ -209,7 +209,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f await settled(); - let chris = store.peekRecord('user', '1'); + const chris = store.peekRecord('user', '1'); await chris.pets; }); @@ -261,7 +261,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // push data, no links store.push({ @@ -291,7 +291,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f }, }); - let chris = store.peekRecord('user', '1'); + const chris = store.peekRecord('user', '1'); await chris.pets; }); @@ -343,7 +343,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // push links, no data store.push({ @@ -427,7 +427,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // push links, no data @@ -514,7 +514,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // push data and links store.push({ @@ -584,7 +584,7 @@ module('integration/relationship/json-api-links | Relationship state updates', f this.owner.register('adapter:application', Adapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // push data, no links store.push({ @@ -674,8 +674,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload hasMany with ${description}`, async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -694,8 +694,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push(deepCopy(payloads.user)); - let pets = await user.pets; + const user = store.push(deepCopy(payloads.user)); + const pets = await user.pets; assert.ok(!!pets, 'We found our pets'); @@ -705,11 +705,11 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get hasMany with ${description}`, async function (assert) { assert.expect(5); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let petRelationshipData = payloads.user.data.relationships.pets.data; - let petRelDataWasEmpty = petRelationshipData && petRelationshipData.length === 0; + const petRelationshipData = payloads.user.data.relationships.pets.data; + const petRelDataWasEmpty = petRelationshipData && petRelationshipData.length === 0; adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -736,8 +736,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push(deepCopy(payloads.user)); - let pets = await user.pets; + const user = store.push(deepCopy(payloads.user)); + const pets = await user.pets; assert.ok(!!pets, 'We found our pets'); @@ -754,11 +754,11 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload belongsTo with ${description}`, async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let homeRelationshipData = payloads.user.data.relationships.home.data; - let homeRelWasEmpty = homeRelationshipData === null; + const homeRelationshipData = payloads.user.data.relationships.home.data; + const homeRelWasEmpty = homeRelationshipData === null; let isInitialFetch = true; let didFetchInitially = false; @@ -784,8 +784,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push(deepCopy(payloads.user)); - let home = user.home; + const user = store.push(deepCopy(payloads.user)); + const home = user.home; await home; if (homeRelWasEmpty) { @@ -801,11 +801,11 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get belongsTo with ${description}`, async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let homeRelationshipData = payloads.user.data.relationships.home.data; - let homeRelWasEmpty = homeRelationshipData === null; + const homeRelationshipData = payloads.user.data.relationships.home.data; + const homeRelWasEmpty = homeRelationshipData === null; adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -823,8 +823,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push(deepCopy(payloads.user)); - let home = await user.home; + const user = store.push(deepCopy(payloads.user)); + const home = await user.home; assert.ok(!!home, 'We found our home'); @@ -975,8 +975,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload hasMany with ${description}`, async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -995,9 +995,9 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user and pets - let user = store.push(deepCopy(payloads.user)); + const user = store.push(deepCopy(payloads.user)); store.push(deepCopy(payloads.pets)); - let pets = await user.pets; + const pets = await user.pets; assert.ok(!!pets, 'We found our pets'); @@ -1007,8 +1007,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get hasMany with ${description}`, async function (assert) { assert.expect(4); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1027,9 +1027,9 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user and pets - let user = store.push(deepCopy(payloads.user)); + const user = store.push(deepCopy(payloads.user)); store.push(deepCopy(payloads.pets)); - let pets = await user.pets; + const pets = await user.pets; assert.ok(!!pets, 'We found our pets'); @@ -1042,8 +1042,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload belongsTo with ${description}`, async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1062,10 +1062,10 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user and home - let user = store.push(deepCopy(payloads.user)); + const user = store.push(deepCopy(payloads.user)); store.push(deepCopy(payloads.home)); await settled(); - let home = user.home; + const home = user.home; await home; @@ -1077,8 +1077,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get belongsTo with ${description}`, async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1097,10 +1097,10 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push(deepCopy(payloads.user)); + const user = store.push(deepCopy(payloads.user)); store.push(deepCopy(payloads.home)); await settled(); - let home = await user.home; + const home = await user.home; assert.ok(!!home, 'We found our home'); @@ -1310,8 +1310,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload hasMany with data, no links`, async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1342,7 +1342,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -1359,7 +1359,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, }, }); - let pets = await user.pets; + const pets = await user.pets; assert.ok(!!pets, 'We found our pets'); @@ -1369,8 +1369,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get hasMany with data, no links`, async function (assert) { assert.expect(5); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1400,7 +1400,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi assert.ok(false, 'We should not call findHasMany'); }; - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -1417,7 +1417,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, }, }); - let pets = await user.pets; + const pets = await user.pets; assert.ok(!!pets, 'We found our pets'); pets.at(0).unloadRecord(); @@ -1429,8 +1429,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload belongsTo with data, no links`, async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1461,7 +1461,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -1478,7 +1478,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, }, }); - let home = user.home; + const home = user.home; await home; assert.ok(!!home, 'We found our home'); @@ -1488,8 +1488,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get belongsTo with data, no links`, async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1520,7 +1520,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -1537,7 +1537,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, }, }); - let home = await user.home; + const home = await user.home; assert.ok(!!home, 'We found our home'); @@ -1550,8 +1550,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload hasMany with missing data setup from the other side, no links`, async function (assert) { assert.expect(4); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1582,7 +1582,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user and pet - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -1609,7 +1609,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, ], }); - let pets = await user.pets; + const pets = await user.pets; assert.strictEqual(pets.length, 1, 'we setup the pets'); assert.ok(!!pets, 'We found our pets'); @@ -1620,8 +1620,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get hasMany with missing data setup from the other side, no links`, async function (assert) { assert.expect(5); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1652,7 +1652,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user and pet - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -1682,7 +1682,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi // should not trigger a fetch bc even though we don't consider `pets` to have complete knowledge // we have no knowledge with which to initate a request. - let pets = await user.pets; + const pets = await user.pets; assert.ok(!!pets, 'We found our pets'); assert.strictEqual(pets.length, 1, 'we loaded our pets'); @@ -1697,8 +1697,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload belongsTo with missing data setup from the other side, no links`, async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1756,7 +1756,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, ], }); - let home = user.home; + const home = user.home; await home; @@ -1767,8 +1767,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+unload+get belongsTo with missing data setup from the other side, no links`, async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1826,8 +1826,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, ], }); - let home = user.home; - let h = await home; + const home = user.home; + const h = await home; assert.ok(!!home, 'We found our home'); @@ -1840,8 +1840,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test(`get+reload hasMany with empty data, no links`, async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.findRecord = () => { @@ -1855,7 +1855,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup user - let user = store.push({ + const user = store.push({ data: { type: 'user', id: '1', @@ -1872,7 +1872,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, }, }); - let pets = user.pets; + const pets = user.pets; await pets; assert.ok(!!pets, 'We found our pets'); @@ -1885,10 +1885,10 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test('We should not fetch a hasMany relationship with links that we know is empty', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let user1Payload = { + const user1Payload = { data: { type: 'user', id: '1', @@ -1905,7 +1905,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }, }, }; - let user2Payload = { + const user2Payload = { data: { type: 'user', id: '2', @@ -1949,8 +1949,8 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup users - let user1 = store.push(deepCopy(user1Payload)); - let user2 = store.push(deepCopy(user2Payload)); + const user1 = store.push(deepCopy(user1Payload)); + const user2 = store.push(deepCopy(user2Payload)); // should not fire a request requestedUser = null; @@ -1975,10 +1975,10 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test('We should not fetch a sync hasMany relationship with a link that is missing the data member', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let petPayload = { + const petPayload = { data: { type: 'pet', id: '1', @@ -2010,7 +2010,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup users - let shen = store.push(petPayload); + const shen = store.push(petPayload); // should not fire a request await shen.pets; @@ -2021,10 +2021,10 @@ module('integration/relationship/json-api-links | Relationship fetching', functi test('We should not fetch a sync belongsTo relationship with a link that is missing the data member', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let petPayload = { + const petPayload = { data: { type: 'pet', id: '1', @@ -2057,7 +2057,7 @@ module('integration/relationship/json-api-links | Relationship fetching', functi }; // setup users - let shen = store.push(petPayload); + const shen = store.push(petPayload); // should not fire a request await shen.owner; diff --git a/tests/main/tests/integration/relationships/many-to-many-test.js b/tests/main/tests/integration/relationships/many-to-many-test.js index 1de6dd9b3a4..0d5f71a867a 100644 --- a/tests/main/tests/integration/relationships/many-to-many-test.js +++ b/tests/main/tests/integration/relationships/many-to-many-test.js @@ -45,7 +45,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', */ test('Loading from one hasMany side reflects on the other hasMany side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -71,7 +71,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }); - let topic = store.push({ + const topic = store.push({ data: { id: '2', type: 'topic', @@ -87,9 +87,9 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Relationship is available from one hasMany side even if only loaded from the other hasMany side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let account = store.push({ + const account = store.push({ data: { id: '2', type: 'account', @@ -121,9 +121,9 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Fetching a hasMany where a record was removed reflects on the other hasMany side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -137,7 +137,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let topic = store.push({ + const topic = store.push({ data: { id: '2', type: 'topic', @@ -161,7 +161,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Fetching a hasMany where a record was removed reflects on the other hasMany side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); let account = store.push({ data: { @@ -172,7 +172,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -217,9 +217,9 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', test('Pushing to a hasMany reflects on the other hasMany side - async', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -233,7 +233,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let topic = store.push({ + const topic = store.push({ data: { id: '2', type: 'topic', @@ -250,9 +250,9 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Pushing to a hasMany reflects on the other hasMany side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let account = store.push({ + const account = store.push({ data: { id: '2', type: 'account', @@ -261,7 +261,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let stanley = store.push({ + const stanley = store.push({ data: { id: '1', type: 'user', @@ -276,7 +276,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Removing a record from a hasMany reflects on the other hasMany side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const user = store.push({ data: { @@ -316,7 +316,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Removing a record from a hasMany reflects on the other hasMany side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const account = store.push({ data: { @@ -358,9 +358,9 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', */ test('Rollbacking attributes for a deleted record that has a ManyToMany relationship works correctly - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -379,7 +379,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let topic = store.push({ + const topic = store.push({ data: { id: '2', type: 'topic', @@ -393,17 +393,17 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', topic.rollbackAttributes(); await settled(); - let users = await topic.users; + const users = await topic.users; assert.strictEqual(users.length, 1, 'Users are still there'); - let topics = await user.topics; + const topics = await user.topics; assert.strictEqual(topics.length, 1, 'Topic got rollbacked into the user'); }); test('Deleting a record that has a hasMany relationship removes it from the otherMany array but does not remove the other record from itself - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let account = store.push({ + const account = store.push({ data: { id: '2', type: 'account', @@ -412,7 +412,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -438,9 +438,9 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Rollbacking attributes for a created record that has a ManyToMany relationship works correctly - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -449,13 +449,13 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let topic = store.createRecord('topic'); + const topic = store.createRecord('topic'); let fetchedTopics = await user.topics; fetchedTopics.push(topic); topic.rollbackAttributes(); - let fetchedUsers = await topic.users; + const fetchedUsers = await topic.users; assert.strictEqual(fetchedUsers.length, 0, 'Users got removed'); assert.strictEqual(fetchedUsers.at(0), undefined, "User can't be fetched"); @@ -465,9 +465,9 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }); test('Deleting an unpersisted record via rollbackAttributes that has a hasMany relationship removes it from the otherMany array but does not remove the other record from itself - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let account = store.push({ + const account = store.push({ data: { id: '2', type: 'account', @@ -477,7 +477,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }); - let user = store.createRecord('user'); + const user = store.createRecord('user'); account.users.push(user); user.rollbackAttributes(); @@ -491,7 +491,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', function (assert) { assert.expect(4); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); let account = store.push({ data: { @@ -502,7 +502,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let ada = store.push({ + const ada = store.push({ data: { id: '1', type: 'user', @@ -521,7 +521,7 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }, }); - let byron = store.push({ + const byron = store.push({ data: { id: '2', type: 'user', @@ -565,8 +565,8 @@ module('integration/relationships/many_to_many_test - ManyToMany relationships', }, }); - let state = account.hasMany('users').hasManyRelationship.remoteState; - let users = account.users; + const state = account.hasMany('users').hasManyRelationship.remoteState; + const users = account.users; assert.todo.strictEqual(users.length, 1, 'Accounts were updated correctly (ui state)'); assert.todo.deepEqual( diff --git a/tests/main/tests/integration/relationships/nested-relationship-test.js b/tests/main/tests/integration/relationships/nested-relationship-test.js index c9332d32e17..6cd3c41478a 100644 --- a/tests/main/tests/integration/relationships/nested-relationship-test.js +++ b/tests/main/tests/integration/relationships/nested-relationship-test.js @@ -36,8 +36,8 @@ module('integration/relationships/nested_relationships_test - Nested relationshi */ test('Sideloaded nested relationships load correctly', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => { return false; @@ -123,18 +123,18 @@ module('integration/relationships/nested_relationships_test - Nested relationshi ], }); - let kid = store.peekRecord('kid', '1'); + const kid = store.peekRecord('kid', '1'); const middleAger = await kid.middleAger; assert.ok(middleAger, 'MiddleAger relationship was set up correctly'); - let middleAgerName = middleAger.name; - let kids = await middleAger.kids; + const middleAgerName = middleAger.name; + const kids = await middleAger.kids; assert.strictEqual(middleAgerName, 'Middle Ager 1', 'MiddleAger name is there'); assert.ok(kids.includes(kid)); const elder = await middleAger.elder; assert.notEqual(elder, null, 'Elder relationship was set up correctly'); - let elderName = elder.name; + const elderName = elder.name; assert.strictEqual(elderName, 'Elder 1', 'Elder name is there'); }); }); diff --git a/tests/main/tests/integration/relationships/one-to-many-test.js b/tests/main/tests/integration/relationships/one-to-many-test.js index 0eda7cf34b8..0f1e830af61 100644 --- a/tests/main/tests/integration/relationships/one-to-many-test.js +++ b/tests/main/tests/integration/relationships/one-to-many-test.js @@ -43,7 +43,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f */ test('Relationship is available from the belongsTo side even if only loaded from the hasMany side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, message; user = store.push({ @@ -80,7 +80,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test("Adapter's findBelongsTo must not be hit when the record is included with its owner", async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.expect(1); this.owner.register( @@ -138,7 +138,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Relationship is available from the belongsTo side even if only loaded from the hasMany side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var account, user; account = store.push({ @@ -173,7 +173,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Relationship is available from the hasMany side even if only loaded from the belongsTo side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, message; user = store.push({ @@ -208,7 +208,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Relationship is available from the hasMany side even if only loaded from the belongsTo side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, account; user = store.push({ @@ -241,7 +241,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Fetching a belongsTo that is set to null removes the record from a relationship - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const user = store.push({ data: { @@ -303,7 +303,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Fetching a belongsTo that is set to null removes the record from a relationship - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user; store.push({ @@ -351,11 +351,11 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }); - assert.strictEqual(user.accounts.at(0), undefined, 'Account was sucesfully removed'); + assert.strictEqual(user.accounts.at(0), undefined, 'Account was successfully removed'); }); test('Fetching a belongsTo that is not defined does not remove the record from a relationship - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user = store.push({ data: { @@ -412,7 +412,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Fetching a belongsTo that is not defined does not remove the record from a relationship - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var account, user; account = store.push({ @@ -453,14 +453,13 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }); - assert.strictEqual(user.accounts.at(0), account, 'Account was sucesfully removed'); + assert.strictEqual(user.accounts.at(0), account, 'Account was successfully removed'); }); test("Fetching the hasMany that doesn't contain the belongsTo, sets the belongsTo to null - async", async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user, message, message2; - user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -479,7 +478,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }, }); - message = store.push({ + const message = store.push({ data: { id: '1', type: 'message', @@ -496,7 +495,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }, }); - message2 = store.push({ + const message2 = store.push({ data: { id: '2', type: 'message', @@ -534,14 +533,10 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test("Fetching the hasMany that doesn't contain the belongsTo, sets the belongsTo to null - sync", function (assert) { - let store = this.owner.lookup('service:store'); - - let account1; - let account2; - let user; + const store = this.owner.lookup('service:store'); // tell the store user:1 has account:1 - user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -557,7 +552,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); // tell the store account:1 has user:1 - account1 = store.push({ + const account1 = store.push({ data: { id: '1', type: 'account', @@ -573,7 +568,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); // tell the store account:2 has no user - account2 = store.push({ + const account2 = store.push({ data: { id: '2', type: 'account', @@ -604,7 +599,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Fetching the hasMany side where the hasMany is undefined does not change the belongsTo side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var message, user; store.push({ @@ -659,7 +654,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Fetching the hasMany side where the hasMany is undefined does not change the belongsTo side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var account, user; store.push({ @@ -725,10 +720,9 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f */ test('Pushing to the hasMany reflects the change on the belongsTo side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user, message2; - user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -756,7 +750,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }, }); - message2 = store.push({ + const message2 = store.push({ data: { id: '2', type: 'message', @@ -775,7 +769,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Pushing to the hasMany reflects the change on the belongsTo side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, account2; user = store.push({ @@ -830,9 +824,9 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Removing from the hasMany side reflects the change on the belongsTo side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user = store.push({ + const user = store.push({ data: { id: '1', type: 'user', @@ -851,7 +845,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }, }); - let message = store.push({ + const message = store.push({ data: { id: '1', type: 'message', @@ -868,12 +862,12 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Removing from the hasMany side reflects the change on the belongsTo side - sync', function (assert) { - let store = this.owner.lookup('service:store'); - let user = store.push({ + const store = this.owner.lookup('service:store'); + const user = store.push({ data: { id: '1', type: 'user', - attirbutes: { + attributes: { name: 'Stanley', }, relationships: { @@ -888,11 +882,11 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }, }); - let account = store.push({ + const account = store.push({ data: { id: '1', type: 'account', - attirbutes: { + attributes: { state: 'great', }, relationships: { @@ -913,7 +907,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f test('Pushing to the hasMany side keeps the oneToMany invariant on the belongsTo side - async', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, user2, message; user = store.push({ @@ -957,11 +951,11 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f await user2.messages.then(async function (fetchedMessages) { fetchedMessages.push(message); - let p1 = message.user.then(function (fetchedUser) { + const p1 = message.user.then(function (fetchedUser) { assert.strictEqual(fetchedUser, user2, 'user got set correctly'); }); - let p2 = user.messages.then(function (newFetchedMessages) { + const p2 = user.messages.then(function (newFetchedMessages) { assert.strictEqual(newFetchedMessages.length, 0, 'message got removed from the old messages hasMany'); }); @@ -970,7 +964,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Pushing to the hasMany side keeps the oneToMany invariant - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, user2, account; user = store.push({ @@ -1019,7 +1013,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f test('Setting the belongsTo side keeps the oneToMany invariant on the hasMany- async', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, user2, message; user = store.push({ @@ -1078,7 +1072,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Setting the belongsTo side keeps the oneToMany invariant on the hasMany- sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, user2, account; user = store.push({ @@ -1135,7 +1129,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f test('Setting the belongsTo side to null removes the record from the hasMany side - async', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, message; user = store.push({ @@ -1185,7 +1179,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Setting the belongsTo side to null removes the record from the hasMany side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, account; user = store.push({ @@ -1236,7 +1230,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f */ test('Rollbacking attributes of a deleted record works correctly when the hasMany side has been deleted - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, message; user = store.push({ @@ -1280,7 +1274,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Rollbacking attributes of a deleted record works correctly when the hasMany side has been deleted - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var account, user; account = store.push({ @@ -1318,7 +1312,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Rollbacking attributes of deleted record works correctly when the belongsTo side has been deleted - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, message; user = store.push({ @@ -1360,7 +1354,7 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Rollbacking attributes of a deleted record works correctly when the belongsTo side has been deleted - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var account, user; account = store.push({ @@ -1402,8 +1396,8 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f */ test('Rollbacking attributes of a created record works correctly when the hasMany side has been created - async', async function (assert) { - let store = this.owner.lookup('service:store'); - let user = store.push({ + const store = this.owner.lookup('service:store'); + const user = store.push({ data: { id: '1', type: 'user', @@ -1412,22 +1406,22 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }, }); - let message = store.createRecord('message', { + const message = store.createRecord('message', { user: user, }); message.rollbackAttributes(); - let fetchedUser = await message.user; + const fetchedUser = await message.user; assert.strictEqual(fetchedUser, null, 'Message does not have the user anymore'); - let fetchedMessages = await user.messages; + const fetchedMessages = await user.messages; assert.strictEqual(fetchedMessages.length, 0, 'User does not have the message anymore'); assert.strictEqual(fetchedMessages.at(0), undefined, "User message can't be accessed"); }); test('Rollbacking attributes of a created record works correctly when the hasMany side has been created - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var user, account; user = store.push({ @@ -1448,8 +1442,8 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }); test('Rollbacking attributes of a created record works correctly when the belongsTo side has been created - async', async function (assert) { - let store = this.owner.lookup('service:store'); - let message = store.push({ + const store = this.owner.lookup('service:store'); + const message = store.push({ data: { id: '2', type: 'message', @@ -1458,20 +1452,20 @@ module('integration/relationships/one_to_many_test - OneToMany relationships', f }, }, }); - let user = store.createRecord('user'); - let messages = await user.messages; + const user = store.createRecord('user'); + const messages = await user.messages; messages.push(message); user.rollbackAttributes(); - let fetchedUser = await message.user; + const fetchedUser = await message.user; assert.strictEqual(fetchedUser, null, 'Message does not have the user anymore'); - let fetchedMessages = await user.messages; + const fetchedMessages = await user.messages; assert.strictEqual(fetchedMessages.length, 0, 'User does not have the message anymore'); assert.strictEqual(fetchedMessages.at(0), undefined, "User message can't be accessed"); }); test('Rollbacking attributes of a created record works correctly when the belongsTo side has been created - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var account, user; account = store.push({ diff --git a/tests/main/tests/integration/relationships/one-to-one-test.js b/tests/main/tests/integration/relationships/one-to-one-test.js index d1718b0ec36..a2ceff7fd8d 100644 --- a/tests/main/tests/integration/relationships/one-to-one-test.js +++ b/tests/main/tests/integration/relationships/one-to-one-test.js @@ -43,7 +43,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun */ test('Relationship is available from both sides even if only loaded from one side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var stanley, stanleysFriend; stanley = store.push({ @@ -79,7 +79,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Relationship is available from both sides even if only loaded from one side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var job, user; job = store.push({ @@ -112,7 +112,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Fetching a belongsTo that is set to null removes the record from a relationship - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var stanleysFriend; stanleysFriend = store.push({ @@ -152,7 +152,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Fetching a belongsTo that is set to null removes the record from a relationship - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var job = store.push({ data: { @@ -198,9 +198,9 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Fetching a belongsTo that is set to a different record, sets the old relationship to null - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user1 = store.push({ + const user1 = store.push({ data: { type: 'user', id: '1', @@ -225,8 +225,8 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun ], }); - let user2 = store.peekRecord('user', '2'); - let user1Friend = await user1.bestFriend; + const user2 = store.peekRecord('user', '2'); + const user1Friend = await user1.bestFriend; assert.strictEqual(user1Friend, user2, '.bestFriend is '); @@ -266,16 +266,16 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun ], }); - let user3 = store.peekRecord('user', '3'); - let user1bestFriend = await user1.bestFriend; - let user2bestFriend = await user2.bestFriend; - let user3bestFriend = await user3.bestFriend; + const user3 = store.peekRecord('user', '3'); + const user1bestFriend = await user1.bestFriend; + const user2bestFriend = await user2.bestFriend; + const user3bestFriend = await user3.bestFriend; assert.strictEqual(user3bestFriend, user2, '.bestFriend is '); assert.strictEqual(user2bestFriend, user3, '.bestFriend is '); assert.strictEqual(user1bestFriend, null, '.bestFriend is null'); - let user1bestFriendState = user1.belongsTo('bestFriend').belongsToRelationship; + const user1bestFriendState = user1.belongsTo('bestFriend').belongsToRelationship; assert.strictEqual(user1bestFriendState.remoteState, null, '.job is canonically empty'); assert.strictEqual(user1bestFriendState.localState, null, '.job is locally empty'); @@ -286,9 +286,9 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Fetching a belongsTo that is set to a different record, sets the old relationship to null - sync', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let user1 = store.push({ + const user1 = store.push({ data: { type: 'user', id: '1', @@ -313,7 +313,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun ], }); - let job1 = store.peekRecord('job', '1'); + const job1 = store.peekRecord('job', '1'); assert.strictEqual(user1.job, job1, '.job is '); @@ -353,13 +353,13 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun ], }); - let user2 = store.peekRecord('user', '2'); + const user2 = store.peekRecord('user', '2'); assert.strictEqual(user2.job, job1, '.job is '); assert.strictEqual(job1.user, user2, '.user is '); assert.strictEqual(user1.job, null, '.job is null'); - let user1JobState = user1.belongsTo('job').belongsToRelationship; + const user1JobState = user1.belongsTo('job').belongsToRelationship; assert.strictEqual(user1JobState.remoteState, null, '.job is canonically empty'); assert.strictEqual(user1JobState.localState, null, '.job is locally empty'); @@ -374,7 +374,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun */ test('Setting a OneToOne relationship reflects correctly on the other side- async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var stanley, stanleysFriend; stanley = store.push({ @@ -402,7 +402,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Setting a OneToOne relationship reflects correctly on the other side- sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var job, user; job = store.push({ @@ -463,7 +463,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Setting a OneToOne relationship to null reflects correctly on the other side - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var stanley, stanleysFriend; stanley = store.push({ @@ -508,7 +508,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Setting a OneToOne relationship to null reflects correctly on the other side - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var job, user; job = store.push({ @@ -553,7 +553,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun test('Setting a belongsTo to a different record, sets the old relationship to null - async', async function (assert) { assert.expect(3); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var stanley, stanleysFriend; stanley = store.push({ @@ -613,7 +613,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Setting a belongsTo to a different record, sets the old relationship to null - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var job, user, newBetterJob; job = store.push({ @@ -667,7 +667,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun */ test('Rollbacking attributes of deleted record restores the relationship on both sides - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var stanley, stanleysFriend; stanley = store.push({ @@ -707,7 +707,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Rollbacking attributes of deleted record restores the relationship on both sides - sync', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var job, user; job = store.push({ @@ -743,7 +743,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Rollbacking attributes of created record removes the relationship on both sides - async', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const stanleysFriend = store.push({ data: { @@ -766,7 +766,7 @@ module('integration/relationships/one_to_one_test - OneToOne relationships', fun }); test('Rollbacking attributes of created record removes the relationship on both sides - sync', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const user = store.push({ data: { diff --git a/tests/main/tests/integration/relationships/relationship-links-test.js b/tests/main/tests/integration/relationships/relationship-links-test.js index 5c0c739899b..b7f1caa77b4 100644 --- a/tests/main/tests/integration/relationships/relationship-links-test.js +++ b/tests/main/tests/integration/relationships/relationship-links-test.js @@ -227,7 +227,7 @@ module('JSON:API links access on relationships', function (hooks) { assert.true(!!links, 'We have a links value on the relationship HasManyReference'); assert.deepEqual(links.related, { href: '/the/related/link' }, 'The related link is correctly available'); - let link = toolsRef.link(); + const link = toolsRef.link(); assert.strictEqual(link, '/the/related/link', 'The related link is unwrapped when accessed directly'); // Test we have access via the ManyArray diff --git a/tests/main/tests/integration/relationships/rollback-test.ts b/tests/main/tests/integration/relationships/rollback-test.ts index 7d71a91432a..8f3c48750fd 100644 --- a/tests/main/tests/integration/relationships/rollback-test.ts +++ b/tests/main/tests/integration/relationships/rollback-test.ts @@ -1,24 +1,28 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import type Store from '@ember-data/store'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; class App extends Model { @attr declare name: string; + @hasMany('config', { async: false, inverse: 'app' }) declare configs: Config[]; + @belongsTo('cluster', { async: false, inverse: 'apps' }) declare cluster: Cluster; } class Cluster extends Model { @attr declare name: string; + @hasMany('app', { async: false, inverse: 'cluster' }) declare apps: App[]; } class Config extends Model { @attr declare name: string; + @belongsTo('app', { async: false, inverse: 'configs' }) declare app: App | null; } diff --git a/tests/main/tests/integration/relationships/unload-new-record-test.js b/tests/main/tests/integration/relationships/unload-new-record-test.js index 8fe1fb4671d..3a10d957904 100644 --- a/tests/main/tests/integration/relationships/unload-new-record-test.js +++ b/tests/main/tests/integration/relationships/unload-new-record-test.js @@ -228,12 +228,12 @@ module('Relationships | unloading new records', function (hooks) { ['5'], 'Precond: entryNode has the correct asyncEdges' ); - let originalRelatedNode = await newNode.relatedGraph; + const originalRelatedNode = await newNode.relatedGraph; assert.strictEqual(originalRelatedNode, null, 'PreCond: newNode has no relatedGraph yet'); set(newNode, 'relatedGraph', entryNode); - let value = await newNode.relatedGraph; + const value = await newNode.relatedGraph; asyncEdges = await entryNode.asyncEdges; assert.strictEqual(value, entryNode, 'PreCond: We properly set the async belongsTo to the new value'); diff --git a/tests/main/tests/integration/request-state-service-test.ts b/tests/main/tests/integration/request-state-service-test.ts index 682322239c7..447ef71b4ba 100644 --- a/tests/main/tests/integration/request-state-service-test.ts +++ b/tests/main/tests/integration/request-state-service-test.ts @@ -10,9 +10,11 @@ import type Store from '@ember-data/store'; class Person extends Model { // TODO fix the typing for naked attrs + @attr('string', {}) name; + @attr('string', {}) lastName; } @@ -23,7 +25,7 @@ module('integration/request-state-service - Request State Service', function (ho let store: Store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.register('serializer:application', JSONSerializer); store = owner.lookup('service:store') as unknown as Store; @@ -32,7 +34,7 @@ module('integration/request-state-service - Request State Service', function (ho test('getPendingRequest and getLastRequest return correct inflight and fulfilled requests', async function (assert) { assert.expect(10); - let normalizedHash = { + const normalizedHash = { data: { type: 'person', id: '1', @@ -45,9 +47,9 @@ module('integration/request-state-service - Request State Service', function (ho included: [], }; - let { owner } = this; + const { owner } = this; - let TestAdapter = EmberObject.extend({ + const TestAdapter = EmberObject.extend({ findRecord() { const personHash = { type: 'person', @@ -74,17 +76,17 @@ module('integration/request-state-service - Request State Service', function (ho store = owner.lookup('service:store') as unknown as Store; - let promise = store.findRecord('person', '1'); - let requestService = store.getRequestStateService(); + const promise = store.findRecord('person', '1'); + const requestService = store.getRequestStateService(); // Relying on sequential lids until identifiers land - let identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); + const identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); normalizedHash.data.lid = identifier.lid; - let request = requestService.getPendingRequestsForRecord(identifier)[0]; + const request = requestService.getPendingRequestsForRecord(identifier)[0]; assert.strictEqual(request.state, 'pending', 'request is pending'); assert.strictEqual(request.type, 'query', 'request is a query'); - let requestOp = { + const requestOp = { op: 'findRecord', recordIdentifier: identifier, options: { @@ -93,9 +95,9 @@ module('integration/request-state-service - Request State Service', function (ho }; assert.deepEqual(request.request.data[0], requestOp, 'request op is correct'); - let person = (await promise) as Model; - let lastRequest = requestService.getLastRequestForRecord(identifier); - let requestStateResult = { + const person = (await promise) as Model; + const lastRequest = requestService.getLastRequestForRecord(identifier); + const requestStateResult = { type: 'query' as const, state: 'fulfilled' as const, request: { data: [requestOp] }, @@ -104,12 +106,12 @@ module('integration/request-state-service - Request State Service', function (ho assert.deepEqual(lastRequest, requestStateResult, 'request is correct after fulfilling'); assert.deepEqual(requestService.getPendingRequestsForRecord(identifier).length, 0, 'no pending requests remaining'); - let savingPromise = person.save(); - let savingRequest = requestService.getPendingRequestsForRecord(identifier)[0]; + const savingPromise = person.save(); + const savingRequest = requestService.getPendingRequestsForRecord(identifier)[0]; assert.strictEqual(savingRequest.state, 'pending', 'request is pending'); assert.strictEqual(savingRequest.type, 'mutation', 'request is a mutation'); - let savingRequestOp = { + const savingRequestOp = { op: 'saveRecord', recordIdentifier: identifier, options: {}, @@ -117,8 +119,8 @@ module('integration/request-state-service - Request State Service', function (ho assert.deepEqual(savingRequest.request.data[0], savingRequestOp, 'request op is correct'); await savingPromise; - let lastSavingRequest = requestService.getLastRequestForRecord(identifier); - let savingRequestStateResult = { + const lastSavingRequest = requestService.getLastRequestForRecord(identifier); + const savingRequestStateResult = { type: 'mutation' as const, state: 'fulfilled' as const, request: { data: [savingRequestOp] }, @@ -137,7 +139,7 @@ module('integration/request-state-service - Request State Service', function (ho name: 'Scumbag Dale', }; - let normalizedHash = { + const normalizedHash = { data: { type: 'person', id: '1', @@ -150,9 +152,9 @@ module('integration/request-state-service - Request State Service', function (ho included: [], }; - let { owner } = this; + const { owner } = this; - let TestAdapter = EmberObject.extend({ + const TestAdapter = EmberObject.extend({ findRecord() { return Promise.resolve(personHash); }, @@ -173,18 +175,18 @@ module('integration/request-state-service - Request State Service', function (ho store = owner.lookup('service:store') as unknown as Store; - let requestService = store.getRequestStateService(); + const requestService = store.getRequestStateService(); // Relying on sequential lids until identifiers land - let identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); + const identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'person', id: '1' }); let count = 0; - let requestOp = { + const requestOp = { op: 'findRecord', recordIdentifier: identifier, options: { reload: true, }, }; - let savingRequestOp = { + const savingRequestOp = { op: 'saveRecord', recordIdentifier: identifier, options: {}, @@ -219,7 +221,7 @@ module('integration/request-state-service - Request State Service', function (ho count++; }); - let person = (await store.findRecord('person', '1')) as Model; + const person = (await store.findRecord('person', '1')) as Model; await person.save(); assert.strictEqual(count, 4, 'callback called four times'); }); diff --git a/tests/main/tests/integration/serializers/embedded-records-mixin-test.js b/tests/main/tests/integration/serializers/embedded-records-mixin-test.js index 2c498c5ac11..6a2337d7aaa 100644 --- a/tests/main/tests/integration/serializers/embedded-records-mixin-test.js +++ b/tests/main/tests/integration/serializers/embedded-records-mixin-test.js @@ -49,7 +49,7 @@ module('integration/embedded-records-mixin', function (hooks) { } hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:super-villain', SuperVillain); owner.register('model:home-planet', HomePlanet); @@ -384,7 +384,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with embedded objects of same type, but from separate attributes', async function (assert) { - let { owner } = this; + const { owner } = this; class HomePlanetKlass extends Model { @attr('string') name; @hasMany('super-villain', { inverse: 'homePlanet', async: false }) villains; @@ -497,7 +497,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with multiply-nested belongsTo', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'serializer:evil-minion', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -588,7 +588,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with polymorphic hasMany and custom primary key', async function (assert) { - let { owner } = this; + const { owner } = this; class SuperVillainClass extends Model { @attr('string') firstName; @attr('string') lastName; @@ -684,7 +684,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with polymorphic belongsTo', async function (assert) { - let { owner } = this; + const { owner } = this; class SuperVillainClass extends Model { @attr('string') firstName; @attr('string') lastName; @@ -754,7 +754,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with polymorphic belongsTo and custom primary key', async function (assert) { - let { owner } = this; + const { owner } = this; class SuperVillainClass extends Model { @attr('string') firstName; @attr('string') lastName; @@ -833,7 +833,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalize with custom belongsTo primary key', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'serializer:evil-minion', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -957,7 +957,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with embedded objects with custom primary key', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'serializer:super-villain', RESTSerializer.extend({ @@ -1187,7 +1187,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with embedded objects of same type, but from separate attributes', async function (assert) { - let { owner } = this; + const { owner } = this; class HomePlanetClass extends Model { @attr('string') name; @hasMany('super-villain', { inverse: 'homePlanet', async: false }) villains; @@ -1454,7 +1454,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('normalizeResponse with polymorphic hasMany', async function (assert) { - let { owner } = this; + const { owner } = this; class SuperVillainClass extends Model { @attr('string') firstName; @@ -1578,20 +1578,20 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123' }); - let secretLab = store.createRecord('secret-lab', { + const homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123' }); + const secretLab = store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: 'California, USA', id: '101', }); - let superVillain = store.createRecord('super-villain', { + const superVillain = store.createRecord('super-villain', { id: '1', firstName: 'Super', lastName: 'Villian', homePlanet, secretLab, }); - let secretWeapon = store.createRecord('secret-weapon', { + const secretWeapon = store.createRecord('secret-weapon', { id: '1', name: 'Secret Weapon', superVillain, @@ -1599,7 +1599,7 @@ module('integration/embedded-records-mixin', function (hooks) { superVillain.secretWeapons.push(secretWeapon); - let evilMinion = store.createRecord('evil-minion', { + const evilMinion = store.createRecord('evil-minion', { id: '1', name: 'Evil Minion', superVillain, @@ -1628,7 +1628,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serializing relationships with an embedded and without calls super when not attr not present', async function (assert) { - let { owner } = this; + const { owner } = this; let calledSerializeBelongsTo = false; let calledSerializeHasMany = false; @@ -1640,12 +1640,12 @@ module('integration/embedded-records-mixin', function (hooks) { serializeHasMany(snapshot, json, relationship) { calledSerializeHasMany = true; - let key = relationship.key; - let payloadKey = this.keyForRelationship ? this.keyForRelationship(key, 'hasMany') : key; - let schema = this.store.modelFor(snapshot.modelName); - let relationshipType = schema.determineRelationshipType(relationship, store); + const key = relationship.key; + const payloadKey = this.keyForRelationship ? this.keyForRelationship(key, 'hasMany') : key; + const schema = this.store.modelFor(snapshot.modelName); + const relationshipType = schema.determineRelationshipType(relationship, store); // "manyToOne" not supported in ActiveModelSerializer.prototype.serializeHasMany - let relationshipTypes = ['manyToNone', 'manyToMany', 'manyToOne']; + const relationshipTypes = ['manyToNone', 'manyToMany', 'manyToOne']; if (relationshipTypes.indexOf(relationshipType) > -1) { json[payloadKey] = snapshot.hasMany(key, { ids: true }); } @@ -1665,30 +1665,30 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { + const homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123', }); - let secretLab = store.createRecord('secret-lab', { + const secretLab = store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: 'California, USA', id: '101', }); - let superVillain = store.createRecord('super-villain', { + const superVillain = store.createRecord('super-villain', { id: '1', firstName: 'Super', lastName: 'Villian', homePlanet, secretLab, }); - let secretWeapon = store.createRecord('secret-weapon', { + const secretWeapon = store.createRecord('secret-weapon', { id: '1', name: 'Secret Weapon', superVillain, }); superVillain.secretWeapons.push(secretWeapon); - let evilMinion = store.createRecord('evil-minion', { + const evilMinion = store.createRecord('evil-minion', { id: '1', name: 'Evil Minion', superVillain, @@ -1729,7 +1729,7 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { + const homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123', }); @@ -1773,7 +1773,7 @@ module('integration/embedded-records-mixin', function (hooks) { }, }) ); - let homePlanet = store.createRecord('home-planet', { + const homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123', }); @@ -1826,7 +1826,7 @@ module('integration/embedded-records-mixin', function (hooks) { }, }); const serializer = store.serializerFor('home-planet'); - let league = store.peekRecord('home-planet', 123); + const league = store.peekRecord('home-planet', 123); let serializedRestJson; const expectedOutput = { name: 'Villain League', @@ -1850,7 +1850,7 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { + const homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123', }); @@ -1880,7 +1880,7 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { + const homePlanet = store.createRecord('home-planet', { name: 'Villain League', id: '123', }); @@ -1920,17 +1920,17 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let superVillain = store.createRecord('super-villain', { + const superVillain = store.createRecord('super-villain', { id: '1', firstName: 'Super', lastName: 'Villian', }); - let evilMinion = store.createRecord('evil-minion', { + const evilMinion = store.createRecord('evil-minion', { id: '1', name: 'Evil Minion', superVillain, }); - let secretWeapon = store.createRecord('secret-weapon', { + const secretWeapon = store.createRecord('secret-weapon', { id: '1', name: 'Secret Weapon', superVillain, @@ -1959,7 +1959,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serialize has many relationship using the `ids-and-types` strategy', async function (assert) { - let { owner } = this; + const { owner } = this; class NormalMinion extends Model { @attr('string') name; } @@ -1983,15 +1983,15 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let yellowMinion = store.createRecord('yellow-minion', { + const yellowMinion = store.createRecord('yellow-minion', { id: '1', name: 'Yellowy', }); - let redMinion = store.createRecord('red-minion', { + const redMinion = store.createRecord('red-minion', { id: '1', name: 'Reddy', }); - let commanderVillain = store.createRecord('commander-villain', { + const commanderVillain = store.createRecord('commander-villain', { id: '1', name: 'Jeff', minions: [yellowMinion, redMinion], @@ -2017,7 +2017,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serializing embedded hasMany respects remapped attrs key', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'serializer:home-planet', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -2036,7 +2036,7 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + const homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); store.createRecord('super-villain', { firstName: 'Ice', lastName: 'Creature', @@ -2062,7 +2062,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serializing ids hasMany respects remapped attrs key', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'serializer:home-planet', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -2081,8 +2081,8 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); - let superVillain = store.createRecord('super-villain', { + const homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + const superVillain = store.createRecord('super-villain', { firstName: 'Ice', lastName: 'Creature', homePlanet, @@ -2110,12 +2110,12 @@ module('integration/embedded-records-mixin', function (hooks) { ); // records with an id, persisted - let secretLab = store.createRecord('secret-lab', { + const secretLab = store.createRecord('secret-lab', { minionCapacity: 5000, vicinity: 'California, USA', id: '101', }); - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2142,7 +2142,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serialize with embedded object (polymorphic belongsTo relationship)', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'serializer:super-villain', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -2162,7 +2162,7 @@ module('integration/embedded-records-mixin', function (hooks) { owner.unregister('model:super-villain'); owner.register('model:super-villain', SuperVillain); - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { id: '1', firstName: 'Tom', lastName: 'Dale', @@ -2201,7 +2201,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serialize with embedded object (belongsTo relationship) works with different primaryKeys', async function (assert) { - let { owner } = this; + const { owner } = this; owner.register( 'serializer:super-villain', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -2221,7 +2221,7 @@ module('integration/embedded-records-mixin', function (hooks) { const superVillainSerializer = store.serializerFor('super-villain'); // records with an id, persisted - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2267,7 +2267,7 @@ module('integration/embedded-records-mixin', function (hooks) { const serializer = store.serializerFor('super-villain'); // records without ids, new - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', secretLab: store.createRecord('secret-lab', { @@ -2291,7 +2291,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serialize with embedded object (polymorphic belongsTo relationship) supports serialize:ids', async function (assert) { - let { owner } = this; + const { owner } = this; class SuperVillain extends Model { @attr('string') firstName; @attr('string') lastName; @@ -2311,7 +2311,7 @@ module('integration/embedded-records-mixin', function (hooks) { owner.unregister('model:super-villain'); owner.register('model:super-villain', SuperVillain); - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2336,7 +2336,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serialize with embedded object (belongsTo relationship) supports serialize:id', async function (assert) { - let { owner } = this; + const { owner } = this; class SuperVillain extends Model { @attr('string') firstName; @attr('string') lastName; @@ -2357,7 +2357,7 @@ module('integration/embedded-records-mixin', function (hooks) { owner.unregister('model:super-villain'); owner.register('model:super-villain', SuperVillain); - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2383,7 +2383,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serialize with embedded object (belongsTo relationship) supports serialize:id in conjunction with deserialize:records', async function (assert) { - let { owner } = this; + const { owner } = this; class SuperVillain extends Model { @attr('string') firstName; @attr('string') lastName; @@ -2404,7 +2404,7 @@ module('integration/embedded-records-mixin', function (hooks) { owner.unregister('model:super-villain'); owner.register('model:super-villain', SuperVillain); - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2444,7 +2444,7 @@ module('integration/embedded-records-mixin', function (hooks) { ); // records with an id, persisted - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2468,7 +2468,7 @@ module('integration/embedded-records-mixin', function (hooks) { assert.deepEqual(serializedRestJson, expectedOutput, 'We serialized the belongsTo relationships to IDs'); }); - test('serialize with embedded object (belongsTo relationship) supports serialize:id', async function (assert) { + test('serialize with embedded object (belongsTo relationship) supports serialize:id, v2', async function (assert) { this.owner.register( 'serializer:super-villain', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -2479,7 +2479,7 @@ module('integration/embedded-records-mixin', function (hooks) { ); // records with an id, persisted - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2503,7 +2503,7 @@ module('integration/embedded-records-mixin', function (hooks) { assert.deepEqual(serializedRestJson, expectedOutput, 'We serialized the belongsTo relationships to IDs'); }); - test('serialize with embedded object (belongsTo relationship) supports serialize:id in conjunction with deserialize:records', async function (assert) { + test('serialize with embedded object (belongsTo relationship) supports serialize:id in conjunction with deserialize:records, v2', async function (assert) { this.owner.register( 'serializer:super-villain', RESTSerializer.extend(EmbeddedRecordsMixin, { @@ -2514,7 +2514,7 @@ module('integration/embedded-records-mixin', function (hooks) { ); // records with an id, persisted - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2549,7 +2549,7 @@ module('integration/embedded-records-mixin', function (hooks) { ); // records with an id, persisted - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2580,7 +2580,7 @@ module('integration/embedded-records-mixin', function (hooks) { this.owner.register('serializer:super-villain', RESTSerializer.extend(EmbeddedRecordsMixin)); // records with an id, persisted - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2614,7 +2614,7 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let tom = store.createRecord('super-villain', { + const tom = store.createRecord('super-villain', { firstName: 'Tom', lastName: 'Dale', id: '1', @@ -2638,7 +2638,7 @@ module('integration/embedded-records-mixin', function (hooks) { }); test('serializing belongsTo correctly removes embedded foreign key', async function (assert) { - let { owner } = this; + const { owner } = this; class SecretWeaponClass extends Model { @attr('string') name; } @@ -2660,8 +2660,8 @@ module('integration/embedded-records-mixin', function (hooks) { owner.register('model:secret-weapon', SecretWeaponClass); owner.register('model:evil-minion', EvilMinionClass); - let secretWeapon = store.createRecord('secret-weapon', { name: 'Secret Weapon' }); - let evilMinion = store.createRecord('evil-minion', { + const secretWeapon = store.createRecord('secret-weapon', { name: 'Secret Weapon' }); + const evilMinion = store.createRecord('evil-minion', { name: 'Evil Minion', secretWeapon, }); @@ -2692,8 +2692,8 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); - let superVillain = store.createRecord('super-villain', { + const homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + const superVillain = store.createRecord('super-villain', { firstName: 'Ice', lastName: 'Creature', homePlanet, @@ -2723,8 +2723,8 @@ module('integration/embedded-records-mixin', function (hooks) { }) ); - let homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); - let superVillain = store.createRecord('super-villain', { + const homePlanet = store.createRecord('home-planet', { name: 'Hoth' }); + const superVillain = store.createRecord('super-villain', { firstName: 'Ice', lastName: 'Creature', homePlanet, diff --git a/tests/main/tests/integration/serializers/json-api-serializer-test.js b/tests/main/tests/integration/serializers/json-api-serializer-test.js index 4032dbf221f..616ea7727c4 100644 --- a/tests/main/tests/integration/serializers/json-api-serializer-test.js +++ b/tests/main/tests/integration/serializers/json-api-serializer-test.js @@ -57,8 +57,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); test('Calling pushPayload works', async function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.pushPayload(store, { data: { @@ -117,8 +117,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); testInDebug('Warns when normalizing an unknown type', function (assert) { - let store = this.owner.lookup('service:store'); - let User = store.modelFor('user'); + const store = this.owner.lookup('service:store'); + const User = store.modelFor('user'); var documentHash = { data: { @@ -136,8 +136,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); testInDebug('Warns when normalizing payload with unknown type included', function (assert) { - let store = this.owner.lookup('service:store'); - let User = store.modelFor('user'); + const store = this.owner.lookup('service:store'); + const User = store.modelFor('user'); var documentHash = { data: { @@ -170,7 +170,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); testInDebug('Warns but does not fail when pushing payload with unknown type included', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var documentHash = { data: { @@ -225,8 +225,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); testInDebug('Warns when normalizing with type missing', function (assert) { - let store = this.owner.lookup('service:store'); - let User = store.modelFor('user'); + const store = this.owner.lookup('service:store'); + const User = store.modelFor('user'); var documentHash = { data: { @@ -254,8 +254,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); - let User = store.modelFor('user'); + const store = this.owner.lookup('service:store'); + const User = store.modelFor('user'); var jsonHash = { data: { @@ -301,7 +301,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var company, user; store.push({ @@ -337,8 +337,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); - let User = store.modelFor('user'); + const store = this.owner.lookup('service:store'); + const User = store.modelFor('user'); var jsonHash = { data: { @@ -365,9 +365,9 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); - let project = store.createRecord('project', { 'company-name': 'Tilde Inc.' }); - let payload = store.serializerFor('project').serialize(project._createSnapshot()); + const store = this.owner.lookup('service:store'); + const project = store.createRecord('project', { 'company-name': 'Tilde Inc.' }); + const payload = store.serializerFor('project').serialize(project._createSnapshot()); assert.strictEqual(payload.data.attributes['company_name'], 'Tilde Inc.'); }); @@ -389,8 +389,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi this.owner.register('model:user', User); - let store = this.owner.lookup('service:store'); - let user = store.createRecord('user', { myCustomField: 'value' }); + const store = this.owner.lookup('service:store'); + const user = store.createRecord('user', { myCustomField: 'value' }); this.owner.register( 'transform:custom', @@ -413,8 +413,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); test('a belongsTo relationship that is not set will not be in the relationships key', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.pushPayload(store, { data: { @@ -423,9 +423,9 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }, }); - let handle = store.peekRecord('handle', 1); + const handle = store.peekRecord('handle', 1); - let serialized = handle.serialize({ includeId: true }); + const serialized = handle.serialize({ includeId: true }); assert.deepEqual(serialized, { data: { type: 'handles', @@ -435,8 +435,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); test('a belongsTo relationship that is set to null will show as null in the relationships key', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.pushPayload(store, { data: { @@ -445,10 +445,10 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }, }); - let handle = store.peekRecord('handle', 1); + const handle = store.peekRecord('handle', 1); handle.set('user', null); - let serialized = handle.serialize({ includeId: true }); + const serialized = handle.serialize({ includeId: true }); assert.deepEqual(serialized, { data: { type: 'handles', @@ -463,8 +463,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); test('a belongsTo relationship set to a new record will not show in the relationships key', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.pushPayload(store, { data: { @@ -473,11 +473,11 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }, }); - let handle = store.peekRecord('handle', 1); - let user = store.createRecord('user'); + const handle = store.peekRecord('handle', 1); + const user = store.createRecord('user'); handle.set('user', user); - let serialized = handle.serialize({ includeId: true }); + const serialized = handle.serialize({ includeId: true }); assert.deepEqual(serialized, { data: { type: 'handles', @@ -496,7 +496,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.serializerFor('user').pushPayload(store, { data: { @@ -517,9 +517,9 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi ], }); - let user = store.peekRecord('user', 1); + const user = store.peekRecord('user', 1); - let serialized = user.serialize({ includeId: true }); + const serialized = user.serialize({ includeId: true }); assert.deepEqual(serialized, { data: { @@ -552,7 +552,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.serializerFor('user').pushPayload(store, { data: { @@ -573,10 +573,10 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi ], }); - let user = store.peekRecord('user', 1); + const user = store.peekRecord('user', 1); store.createRecord('handle', { user }); - let serialized = user.serialize({ includeId: true }); + const serialized = user.serialize({ includeId: true }); assert.deepEqual(serialized, { data: { @@ -609,7 +609,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.serializerFor('user').pushPayload(store, { data: { @@ -618,10 +618,10 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }, }); - let user = store.peekRecord('user', 1); + const user = store.peekRecord('user', 1); store.createRecord('handle', { user }); - let serialized = user.serialize({ includeId: true }); + const serialized = user.serialize({ includeId: true }); assert.deepEqual(serialized, { data: { @@ -651,7 +651,7 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.serializerFor('user').pushPayload(store, { data: { @@ -672,15 +672,15 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi ], }); - let user = store.peekRecord('user', '1'); - let handle1 = store.peekRecord('handle', '1'); - let handle2 = store.peekRecord('handle', '2'); + const user = store.peekRecord('user', '1'); + const handle1 = store.peekRecord('handle', '1'); + const handle2 = store.peekRecord('handle', '2'); const handles = await user.handles; handles.splice(handles.indexOf(handle1), 1); handles.splice(handles.indexOf(handle2), 1); - let serialized = user.serialize({ includeId: true }); + const serialized = user.serialize({ includeId: true }); assert.deepEqual(serialized, { data: { @@ -715,8 +715,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi }); testInDebug('Asserts when normalized attribute key is not found in payload but original key is', function (assert) { - let store = this.owner.lookup('service:store'); - let User = store.modelFor('user'); + const store = this.owner.lookup('service:store'); + const User = store.modelFor('user'); var jsonHash = { data: { @@ -736,8 +736,8 @@ module('integration/serializers/json-api-serializer - JSONAPISerializer', functi testInDebug( 'Asserts when normalized relationship key is not found in payload but original key is', function (assert) { - let store = this.owner.lookup('service:store'); - let User = store.modelFor('user'); + const store = this.owner.lookup('service:store'); + const User = store.modelFor('user'); var jsonHash = { data: { diff --git a/tests/main/tests/integration/serializers/json-serializer-test.js b/tests/main/tests/integration/serializers/json-serializer-test.js index 1d759469d33..8df9c892aef 100644 --- a/tests/main/tests/integration/serializers/json-serializer-test.js +++ b/tests/main/tests/integration/serializers/json-serializer-test.js @@ -22,8 +22,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }); test("serialize doesn't include ID when includeId is false", function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); class Post extends Model { @attr('string') title; @@ -37,11 +37,11 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let post = store.createRecord('post', { + const post = store.createRecord('post', { title: 'Rails is omakase', comments: [], }); - let json = serializer.serialize(post._createSnapshot(), { includeId: false }); + const json = serializer.serialize(post._createSnapshot(), { includeId: false }); assert.deepEqual(json, { title: 'Rails is omakase', @@ -50,8 +50,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }); test("serialize doesn't include relationship if not aware of one", function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); class Post extends Model { @attr('string') title; @@ -65,8 +65,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let json = serializer.serialize(post._createSnapshot()); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const json = serializer.serialize(post._createSnapshot()); assert.deepEqual(json, { title: 'Rails is omakase', @@ -74,8 +74,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }); test('serialize includes id when includeId is true', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); class Post extends Model { @attr('string') title; @@ -89,11 +89,11 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let post = store.createRecord('post', { title: 'Rails is omakase', comments: [] }); + const post = store.createRecord('post', { title: 'Rails is omakase', comments: [] }); post.set('id', 'test'); - let json = serializer.serialize(post._createSnapshot(), { includeId: true }); + const json = serializer.serialize(post._createSnapshot(), { includeId: true }); assert.deepEqual(json, { id: 'test', @@ -115,10 +115,10 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let json = {}; + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const json = {}; serializer.serializeAttribute(post._createSnapshot(), json, 'title', { type: 'string' }); @@ -149,9 +149,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let json = {}; + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const json = {}; store.serializerFor('post').serializeAttribute(post._createSnapshot(), json, 'title', { type: 'string' }); @@ -171,11 +171,11 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); - let post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); - let json = {}; + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + const post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const json = {}; serializer.serializeBelongsTo(comment._createSnapshot(), json, comment.constructor.relationshipsByName.get('post')); @@ -195,10 +195,10 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: null }); - let json = {}; + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: null }); + const json = {}; serializer.serializeBelongsTo(comment._createSnapshot(), json, comment.constructor.relationshipsByName.get('post')); @@ -224,10 +224,10 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: null }); - let json = {}; + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: null }); + const json = {}; serializer.serializeBelongsTo(comment._createSnapshot(), json, comment.constructor.relationshipsByName.get('post')); @@ -262,10 +262,10 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); - let json = {}; + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const json = {}; store .serializerFor('post') @@ -298,9 +298,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); - let comment = store.createRecord('comment', { + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post, id: '1', @@ -308,7 +308,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { post.comments.push(comment); - let json = {}; + const json = {}; store .serializerFor('post') @@ -332,9 +332,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let post = store.push({ + const post = store.push({ data: { id: '1', type: 'post', @@ -343,7 +343,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }, }, }); - let json = {}; + const json = {}; store .serializerFor('post') @@ -365,8 +365,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); store.createRecord('comment', { body: 'Omakase is delicious', post: post, id: '1' }); var snapshot = post._createSnapshot(); @@ -391,10 +391,10 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('model:post', Post); this.owner.register('model:comment', Comment); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); - let post = store.createRecord('post', { title: 'Rails is omakase', comments: [] }); - let json = {}; + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + const post = store.createRecord('post', { title: 'Rails is omakase', comments: [] }); + const json = {}; serializer.serializeIntoHash(json, store.modelFor('post'), post._createSnapshot()); @@ -423,8 +423,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { 'serializer:comment', JSONSerializer.extend({ serializePolymorphicType(record, json, relationship) { - let key = relationship.key; - let belongsTo = record.belongsTo(key); + const key = relationship.key; + const belongsTo = record.belongsTo(key); json[relationship.key + 'TYPE'] = belongsTo.modelName; assert.ok(true, 'serializePolymorphicType is called when serialize a polymorphic belongsTo'); @@ -432,9 +432,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); store .serializerFor('comment') @@ -464,9 +464,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase', id: '1' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); store .serializerFor('comment') @@ -502,7 +502,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.serializerFor('post').normalizeResponse(store, store.modelFor('post'), posts, null, 'findAll'); @@ -538,7 +538,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { my_comments: [1, 2], }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = store .serializerFor('post') .normalizeResponse(store, store.modelFor('post'), jsonHash, '1', 'findRecord'); @@ -572,7 +572,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { author_name_key: 'DHH', }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = store .serializerFor('post') @@ -605,9 +605,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let parentPost = store.push({ + const parentPost = store.push({ data: { type: 'post', id: '2', @@ -616,11 +616,11 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }, }, }); - let post = store.createRecord('post', { + const post = store.createRecord('post', { title: 'Rails is omakase', parentPost: parentPost, }); - let payload = store.serializerFor('post').serialize(post._createSnapshot()); + const payload = store.serializerFor('post').serialize(post._createSnapshot()); assert.strictEqual(payload.title_payload_key, 'Rails is omakase'); assert.strictEqual(payload.my_parent, '2'); @@ -657,7 +657,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }, }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var Parent = store.modelFor('parent'); var payload = store.serializerFor('parent').normalizeResponse(store, Parent, jsonHash, '1', 'findRecord'); assert.deepEqual(payload.included, [ @@ -704,7 +704,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }, }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var Parent = store.modelFor('parent'); var payload = store.serializerFor('parent').normalizeResponse(store, Parent, jsonHash, '1', 'findRecord'); assert.deepEqual(payload.included, [ @@ -747,9 +747,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let payload = store.serializerFor('post').serialize(post._createSnapshot()); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const payload = store.serializerFor('post').serialize(post._createSnapshot()); assert.notOk(hasOwn(payload, 'title'), 'Does not add the key to instance'); assert.notOk(hasOwn(payload, '[object Object]'), 'Does not add some random key like [object Object]'); @@ -778,8 +778,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); store.createRecord('comment', { body: 'Omakase is delicious', post: post }); var serializer = store.serializerFor('post'); @@ -812,9 +812,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); var serializer = store.serializerFor('comment'); var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); @@ -823,7 +823,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { assert.notOk(hasOwn(payload, serializedProperty), 'Does not add the key to instance'); }); - test('Serializer respects `serialize: false` on the attrs hash for a `hasMany` property', function (assert) { + test('Serializer respects `serialize: false` on the attrs hash for a `hasMany` property, v2', function (assert) { assert.expect(1); class Post extends Model { @attr('string') title; @@ -846,8 +846,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); store.createRecord('comment', { body: 'Omakase is delicious', post: post }); var serializer = store.serializerFor('post'); @@ -857,7 +857,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { assert.notOk(hasOwn(payload, serializedProperty), 'Does not add the key to instance'); }); - test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo` property', function (assert) { + test('Serializer respects `serialize: false` on the attrs hash for a `belongsTo` property, v2', function (assert) { assert.expect(1); class Post extends Model { @attr('string') title; @@ -880,9 +880,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); var serializer = store.serializerFor('comment'); var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); @@ -914,9 +914,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); const comments = await post.comments; comments.push(comment); @@ -951,9 +951,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Rails is omakase' }); - let comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase' }); + const comment = store.createRecord('comment', { body: 'Omakase is delicious', post: post }); var serializer = store.serializerFor('comment'); var serializedProperty = serializer.keyForRelationship('post', 'belongsTo'); @@ -994,13 +994,13 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Rails is omakase', description: 'Omakase is delicious', anotherString: 'yet another string', }); - let payload = store.serializerFor('post').serialize(post._createSnapshot()); + const payload = store.serializerFor('post').serialize(post._createSnapshot()); assert.strictEqual(payload.title_payload_key, 'Rails is omakase'); assert.strictEqual(payload.description_payload_key, 'Omakase is delicious'); @@ -1030,9 +1030,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let jsonHash = { _ID_: 1, title: 'Rails is omakase' }; - let store = this.owner.lookup('service:store'); - let post = store + const jsonHash = { _ID_: 1, title: 'Rails is omakase' }; + const store = this.owner.lookup('service:store'); + const post = store .serializerFor('post') .normalizeResponse(store, store.modelFor('post'), jsonHash, '1', 'findRecord'); @@ -1061,9 +1061,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { id: '1', title: 'Rails is omakase' }); - let payload = store.serializerFor('post').serialize(post._createSnapshot(), { includeId: true }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { id: '1', title: 'Rails is omakase' }); + const payload = store.serializerFor('post').serialize(post._createSnapshot(), { includeId: true }); assert.strictEqual(payload._ID_, '1'); }); @@ -1091,9 +1091,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let jsonHash = { id: '1', TITLE: 'Rails is omakase' }; - let store = this.owner.lookup('service:store'); - let post = store.serializerFor('post').normalize(store.modelFor('post'), jsonHash); + const jsonHash = { id: '1', TITLE: 'Rails is omakase' }; + const store = this.owner.lookup('service:store'); + const post = store.serializerFor('post').normalize(store.modelFor('post'), jsonHash); assert.strictEqual(post.data.id, '1'); assert.strictEqual(post.data.attributes.title, 'Rails is omakase'); @@ -1122,9 +1122,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let jsonHash = { id: '1', title: 'Rails is omakase', COMMENTS: ['1'] }; - let store = this.owner.lookup('service:store'); - let post = store.serializerFor('post').normalize(store.modelFor('post'), jsonHash); + const jsonHash = { id: '1', title: 'Rails is omakase', COMMENTS: ['1'] }; + const store = this.owner.lookup('service:store'); + const post = store.serializerFor('post').normalize(store.modelFor('post'), jsonHash); assert.deepEqual(post.data.relationships.comments.data, [{ id: '1', type: 'comment' }]); }); @@ -1163,7 +1163,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var normalizedPayload = store.serializerFor('post').normalize(store.modelFor('post'), { id: '1', @@ -1219,9 +1219,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let post = store.createRecord('post', { title: 'Kitties are omakase', id: '1' }); - let favorite = store.createRecord('favorite', { post: post, id: '3' }); + const store = this.owner.lookup('service:store'); + const post = store.createRecord('post', { title: 'Kitties are omakase', id: '1' }); + const favorite = store.createRecord('favorite', { post: post, id: '3' }); store .serializerFor('favorite') @@ -1275,7 +1275,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { ], }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var errors = store.serializerFor('post').extractErrors(store, store.modelFor('post'), payload); assert.deepEqual(errors, { @@ -1309,7 +1309,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { this.owner.register('serializer:post', JSONSerializer.extend()); var payload = { - attributeWhichWillBeRemovedinExtractErrors: ['true'], + attributeWhichWillBeRemovedInExtractErrors: ['true'], errors: [ { source: { pointer: 'data/attributes/title' }, @@ -1318,7 +1318,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { ], }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var errors = store.serializerFor('post').extractErrors(store, store.modelFor('post'), payload); assert.deepEqual(errors, { title: ['title errors'] }); @@ -1352,7 +1352,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { untouchedSinceNoErrorsSiblingPresent: ['true'], }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var errors = store.serializerFor('post').extractErrors(store, store.modelFor('post'), payload); assert.deepEqual(errors, { untouchedSinceNoErrorsSiblingPresent: ['true'] }); @@ -1384,7 +1384,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { 'serializer:post', JSONSerializer.extend({ extractMeta(store, modelClass, payload) { - let meta = this._super(...arguments); + const meta = this._super(...arguments); meta.authors.push('Tomhuda'); return meta; }, @@ -1400,7 +1400,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }, }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = store .serializerFor('post') .normalizeResponse(store, store.modelFor('post'), jsonHash, '1', 'findRecord'); @@ -1437,7 +1437,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { title: 'Rails is omakase', }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = store .serializerFor('post') .normalizeResponse(store, store.modelFor('post'), jsonHash, '1', 'findRecord'); @@ -1475,7 +1475,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { comments: null, }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = store .serializerFor('post') .normalizeResponse(store, store.modelFor('post'), jsonHash, '1', 'findRecord'); @@ -1524,7 +1524,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { ], }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = store .serializerFor('post') .normalizeResponse(store, store.modelFor('post'), jsonHash, '1', 'findRecord'); @@ -1583,7 +1583,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }, ]; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = store.serializerFor('post').normalizeResponse(store, store.modelFor('post'), payload, '1', 'findAll'); assert.deepEqual(post.included, [ @@ -1631,7 +1631,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { title: 'Rails is omakase', }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.expectWarning(function () { var post = store @@ -1675,9 +1675,9 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('post'); - let post = store.createRecord('post', { custom: 'value' }); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('post'); + const post = store.createRecord('post', { custom: 'value' }); serializer.serialize(post._createSnapshot()); }); @@ -1716,8 +1716,8 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('post'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('post'); serializer.normalize(store.modelFor('post'), { custom: 'value', @@ -1764,7 +1764,7 @@ module('integration/serializer/json - JSONSerializer', function (hooks) { }, }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); var post = this.owner.lookup('serializer:post').normalizeSingleResponse(store, store.modelFor('post'), jsonHash); assert.strictEqual(post.data.attributes.title, 'Rails is omakase'); diff --git a/tests/main/tests/integration/serializers/rest-serializer-test.js b/tests/main/tests/integration/serializers/rest-serializer-test.js index 5683626ad25..262a67834a0 100644 --- a/tests/main/tests/integration/serializers/rest-serializer-test.js +++ b/tests/main/tests/integration/serializers/rest-serializer-test.js @@ -67,11 +67,11 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { test('modelNameFromPayloadKey returns always same modelName even for uncountable multi words keys', function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); Inflector.inflector.uncountable('words'); - let expectedModelName = 'multi-words'; + const expectedModelName = 'multi-words'; assert.strictEqual(serializer.modelNameFromPayloadKey('multi_words'), expectedModelName); assert.strictEqual(serializer.modelNameFromPayloadKey('multi-words'), expectedModelName); @@ -82,21 +82,21 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { 'serializer:home-planet', RESTSerializer.extend({ extractMeta(store, modelClass, payload) { - let meta = this._super(...arguments); + const meta = this._super(...arguments); meta.authors.push('Tomhuda'); return meta; }, }) ); - let jsonHash = { + const jsonHash = { meta: { authors: ['Tomster'] }, home_planets: [{ id: '1', name: 'Umber', superVillains: [1] }], }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let json = store + const json = store .serializerFor('home-planet') .normalizeResponse(store, store.modelFor('home-planet'), jsonHash, null, 'findAll'); @@ -106,8 +106,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { test('normalizeResponse with custom modelNameFromPayloadKey', function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.modelNameFromPayloadKey = function (root) { return root === 'planets' ? 'home-planet' : singularize(dasherize(root)); @@ -116,7 +116,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { this.owner.register('serializer:home-planet', JSONSerializer.extend()); this.owner.register('serializer:super-villain', JSONSerializer.extend()); - let jsonHash = { + const jsonHash = { planets: [ { id: '1', @@ -133,7 +133,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }, ], }; - let array = serializer.normalizeResponse(store, store.modelFor('home-planet'), jsonHash, '1', 'findRecord'); + const array = serializer.normalizeResponse(store, store.modelFor('home-planet'), jsonHash, '1', 'findRecord'); assert.deepEqual(array, { data: { @@ -169,8 +169,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { testInDebug('normalizeResponse with type and custom modelNameFromPayloadKey', function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); let homePlanetNormalizeCount = 0; @@ -188,10 +188,10 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }) ); - let jsonHash = { + const jsonHash = { 'my-custom-type': [{ id: '1', name: 'Umber', type: 'my-custom-type' }], }; - let array = serializer.normalizeResponse(store, store.modelFor('home-planet'), jsonHash, '1', 'findAll'); + const array = serializer.normalizeResponse(store, store.modelFor('home-planet'), jsonHash, '1', 'findAll'); assert.deepEqual(array, { data: [ @@ -210,11 +210,11 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); testInDebug('normalizeResponse warning with custom modelNameFromPayloadKey', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); let homePlanet; - let oldModelNameFromPayloadKey = serializer.modelNameFromPayloadKey; + const oldModelNameFromPayloadKey = serializer.modelNameFromPayloadKey; this.owner.register('serializer:super-villain', JSONSerializer.extend()); this.owner.register('serializer:home-planet', JSONSerializer.extend()); @@ -246,8 +246,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); testInDebug('normalizeResponse warning with custom modelNameFromPayloadKey (again)', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); let homePlanets; this.owner.register('serializer:super-villain', JSONSerializer); @@ -284,12 +284,12 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('serialize polymorphicType', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - let tom = store.createRecord('yellow-minion', { name: 'Alex', id: '124' }); - let ray = store.createRecord('doomsday-device', { evilMinion: tom, name: 'DeathRay' }); - let json = serializer.serialize(ray._createSnapshot()); + const tom = store.createRecord('yellow-minion', { name: 'Alex', id: '124' }); + const ray = store.createRecord('doomsday-device', { evilMinion: tom, name: 'DeathRay' }); + const json = serializer.serialize(ray._createSnapshot()); assert.deepEqual(json, { name: 'DeathRay', @@ -299,21 +299,21 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('serialize polymorphicType with decamelized modelName', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - let tom = store.createRecord('yellow-minion', { name: 'Alex', id: '124' }); - let ray = store.createRecord('doomsday-device', { evilMinion: tom, name: 'DeathRay' }); - let json = serializer.serialize(ray._createSnapshot()); + const tom = store.createRecord('yellow-minion', { name: 'Alex', id: '124' }); + const ray = store.createRecord('doomsday-device', { evilMinion: tom, name: 'DeathRay' }); + const json = serializer.serialize(ray._createSnapshot()); assert.deepEqual(json['evilMinionType'], 'yellowMinion'); }); test('serialize polymorphic when associated object is null', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); - let ray = store.createRecord('doomsday-device', { name: 'DeathRay' }); - let json = serializer.serialize(ray._createSnapshot()); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + const ray = store.createRecord('doomsday-device', { name: 'DeathRay' }); + const json = serializer.serialize(ray._createSnapshot()); assert.deepEqual(json['evilMinionType'], null); }); @@ -332,13 +332,13 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }) ); - let jsonHash = { + const jsonHash = { evilMinion: { id: '1', name: 'Tom Dale', superVillain: 1 }, superVillains: [{ id: '1', firstName: 'Yehuda', lastName: 'Katz', homePlanet: '1' }], }; - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, '1', 'findRecord'); @@ -348,20 +348,19 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { test('normalizeResponse returns null if payload contains null', function (assert) { assert.expect(1); - let jsonHash = { + const jsonHash = { evilMinion: null, }; - let value; - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - value = serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, null, 'findRecord'); + const value = serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, null, 'findRecord'); assert.deepEqual(value, { data: null, included: [] }, 'returned value is null'); }); - test('normalizeResponse loads secondary records with correct serializer', function (assert) { + test('normalizeResponse loads secondary records with correct serializer, v2', function (assert) { let superVillainNormalizeCount = 0; this.owner.register('serializer:evil-minion', JSONSerializer); @@ -375,13 +374,13 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }) ); - let jsonHash = { + const jsonHash = { evilMinions: [{ id: '1', name: 'Tom Dale', superVillain: 1 }], superVillains: [{ id: '1', firstName: 'Yehuda', lastName: 'Katz', homePlanet: '1' }], }; - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, null, 'findAll'); @@ -392,23 +391,23 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { this.owner.register('serializer:super-villain', RESTSerializer); this.owner.register('serializer:evil-minion', RESTSerializer); - let evilMinions = []; - // The actual stack size seems to vary based on browser and potenetially hardware and + const evilMinions = []; + // The actual stack size seems to vary based on browser and potentially hardware and // other factors. This number should be large enough to always be an issue. - let stackOverflowSize = 130000; + const stackOverflowSize = 130000; for (let i = 0; i < stackOverflowSize; i++) { evilMinions.push({ id: i.toString(), superVillain: 1 }); } - let jsonHash = { + const jsonHash = { superVillains: [{ id: '1', firstName: 'Yehuda', lastName: 'Katz', homePlanet: '1' }], evilMinions, }; let superVillain; try { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); superVillain = serializer.normalizeResponse(store, store.modelFor('super-villain'), jsonHash, null, 'findAll'); } catch (err) { assert.ok(false, `normalizeResponse could not handle included length of ${stackOverflowSize}`); @@ -432,15 +431,14 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }) ); - let jsonHash = { + const jsonHash = { evilMinions: [{ id: '1', name: 'Tom Dale', is_super_villain: 1 }], }; - let array; - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - array = serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, null, 'findAll'); + const array = serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, null, 'findAll'); assert.strictEqual(array.data[0].relationships.superVillain.data.id, '1'); }); @@ -458,24 +456,23 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }) ); - let jsonHash = { + const jsonHash = { evilMinions: [{ id: '1', full_name: 'Tom Dale' }], }; - let array; - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - array = serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, null, 'findAll'); + const array = serializer.normalizeResponse(store, store.modelFor('evil-minion'), jsonHash, null, 'findAll'); assert.strictEqual(array.data[0].attributes.name, 'Tom Dale'); }); test('serializeIntoHash', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); - let league = store.createRecord('home-planet', { name: 'Umber', id: '123' }); - let json = {}; + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + const league = store.createRecord('home-planet', { name: 'Umber', id: '123' }); + const json = {}; serializer.serializeIntoHash(json, store.modelFor('home-planet'), league._createSnapshot()); @@ -487,11 +484,11 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('serializeIntoHash with decamelized modelName', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - let league = store.createRecord('home-planet', { name: 'Umber', id: '123' }); - let json = {}; + const league = store.createRecord('home-planet', { name: 'Umber', id: '123' }); + const json = {}; serializer.serializeIntoHash(json, store.modelFor('home-planet'), league._createSnapshot()); @@ -503,13 +500,13 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('serializeBelongsTo with async polymorphic', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - let json = {}; - let expected = { evilMinion: '1', evilMinionType: 'evilMinion' }; - let evilMinion = store.createRecord('evil-minion', { id: '1', name: 'Tomster' }); - let doomsdayDevice = store.createRecord('doomsday-device', { + const json = {}; + const expected = { evilMinion: '1', evilMinionType: 'evilMinion' }; + const evilMinion = store.createRecord('evil-minion', { id: '1', name: 'Tomster' }); + const doomsdayDevice = store.createRecord('doomsday-device', { id: '2', name: 'Yehuda', evilMinion: evilMinion, @@ -525,18 +522,18 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('keyForPolymorphicType can be used to overwrite how the type of a polymorphic record is serialized', function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - let json = {}; - let expected = { evilMinion: '1', typeForEvilMinion: 'evilMinion' }; + const json = {}; + const expected = { evilMinion: '1', typeForEvilMinion: 'evilMinion' }; serializer.keyForPolymorphicType = function () { return 'typeForEvilMinion'; }; - let evilMinion = store.createRecord('evil-minion', { id: '1', name: 'Tomster' }); - let doomsdayDevice = store.createRecord('doomsday-device', { + const evilMinion = store.createRecord('evil-minion', { id: '1', name: 'Tomster' }); + const doomsdayDevice = store.createRecord('doomsday-device', { id: '2', name: 'Yehuda', evilMinion: evilMinion, @@ -552,7 +549,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('keyForPolymorphicType can be used to overwrite how the type of a polymorphic record is looked up for normalization', function (assert) { - let json = { + const json = { doomsdayDevice: { id: '1', evilMinion: '2', @@ -560,7 +557,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }, }; - let expected = { + const expected = { data: { type: 'doomsday-device', id: '1', @@ -577,22 +574,22 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { included: [], }; - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); serializer.keyForPolymorphicType = function () { return 'typeForEvilMinion'; }; - let normalized = serializer.normalizeResponse(store, store.modelFor('doomsday-device'), json, null, 'findRecord'); + const normalized = serializer.normalizeResponse(store, store.modelFor('doomsday-device'), json, null, 'findRecord'); assert.deepEqual(normalized, expected, 'normalized JSON is correct'); }); test('serializeIntoHash uses payloadKeyFromModelName to normalize the payload root key', function (assert) { - let store = this.owner.lookup('service:store'); - let league = store.createRecord('home-planet', { name: 'Umber', id: '123' }); - let json = {}; + const store = this.owner.lookup('service:store'); + const league = store.createRecord('home-planet', { name: 'Umber', id: '123' }); + const json = {}; this.owner.register( 'serializer:home-planet', @@ -603,7 +600,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }) ); - let serializer = store.serializerFor('home-planet'); + const serializer = store.serializerFor('home-planet'); serializer.serializeIntoHash(json, store.modelFor('home-planet'), league._createSnapshot()); @@ -648,8 +645,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('normalizeResponse with async polymorphic belongsTo', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = () => { return { @@ -705,8 +702,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { this.owner.register('model:evil-minion', EvilMinion); this.owner.register('model:yellow-minion', YellowMinion); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = () => { return { @@ -748,20 +745,19 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test('normalizeResponse can load secondary records of the same type without affecting the query count', function (assert) { - let jsonHash = { + const jsonHash = { comments: [{ id: '1', body: 'Parent Comment', root: true, children: [2, 3] }], _comments: [ { id: '2', body: 'Child Comment 1', root: false }, { id: '3', body: 'Child Comment 2', root: false }, ], }; - let array; this.owner.register('serializer:comment', JSONSerializer); - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); - array = serializer.normalizeResponse(store, Comment, jsonHash, '1', 'findRecord'); + const array = serializer.normalizeResponse(store, Comment, jsonHash, '1', 'findRecord'); assert.deepEqual(array, { data: { @@ -804,8 +800,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test("don't polymorphically deserialize base on the type key in payload when a type attribute exist", async function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); store.push( serializer.normalizeArrayResponse(store, store.modelFor('basket'), { @@ -828,8 +824,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test("don't polymorphically deserialize base on the type key in payload when a type attribute exist on a singular response", function (assert) { - let store = this.owner.lookup('service:store'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); store.push( serializer.normalizeSingleResponse( @@ -849,8 +845,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }); test("don't polymorphically deserialize based on the type key in payload when a relationship exists named type", async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = () => { return { @@ -882,7 +878,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }) ); - let jsonHash = { + const jsonHash = { 'super-villains': [ { firstName: 'Tom', @@ -894,9 +890,9 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { ], }; - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let documentHash = store + const documentHash = store .serializerFor('super-villain') .normalizeSingleResponse(store, store.modelFor('super-villain'), jsonHash); @@ -908,7 +904,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { this.owner.register('serializer:evil-minion', JSONSerializer); this.owner.register('serializer:doomsday-device', RESTSerializer.extend()); - let payload = { + const payload = { doomsdayDevice: { id: '1', evilMinion: 2, @@ -919,8 +915,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }, }; - let store = this.owner.lookup('service:store'); - let document = store + const store = this.owner.lookup('service:store'); + const document = store .serializerFor('doomsday-device') .normalizeSingleResponse(store, store.modelFor('doomsday-device'), payload); @@ -946,7 +942,7 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { this.owner.register('serializer:super-villain', JSONSerializer); this.owner.register('serializer:home-planet', RESTSerializer.extend()); - let payload = { + const payload = { homePlanet: { id: '1', superVillains: [2], @@ -957,8 +953,8 @@ module('integration/serializer/rest - RESTSerializer', function (hooks) { }, }; - let store = this.owner.lookup('service:store'); - let document = store + const store = this.owner.lookup('service:store'); + const document = store .serializerFor('home-planet') .normalizeSingleResponse(store, store.modelFor('home-planet'), payload); diff --git a/tests/main/tests/integration/snapshot-test.js b/tests/main/tests/integration/snapshot-test.js index 5055084d2c3..f3f35d7cf0d 100644 --- a/tests/main/tests/integration/snapshot-test.js +++ b/tests/main/tests/integration/snapshot-test.js @@ -53,9 +53,9 @@ module('integration/snapshot - Snapshot', function (hooks) { } owner.register('model:address', Address); - let newAddress = store.createRecord('address', {}); - let snapshot = newAddress._createSnapshot(); - let expected = { + const newAddress = store.createRecord('address', {}); + const snapshot = newAddress._createSnapshot(); + const expected = { country: 'USA', state: 'CA', street: undefined, @@ -79,8 +79,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); assert.ok(snapshot instanceof Snapshot, 'snapshot is an instance of Snapshot'); }); @@ -97,8 +97,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); assert.strictEqual(snapshot.id, '1', 'id is correct'); assert.strictEqual(snapshot.modelName, 'post', 'modelName is correct'); @@ -138,9 +138,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }); - let identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'post', id: '1' }); - let snapshot = store._fetchManager.createSnapshot(identifier); - let expected = { + const identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'post', id: '1' }); + const snapshot = store._fetchManager.createSnapshot(identifier); + const expected = { author: undefined, title: 'Hello World', }; @@ -163,9 +163,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }); - let identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'post', id: '1' }); - let snapshot = store._fetchManager.createSnapshot(identifier); - let expected = { + const identifier = store.identifierCache.getOrCreateRecordIdentifier({ type: 'post', id: '1' }); + const snapshot = store._fetchManager.createSnapshot(identifier); + const expected = { author: undefined, title: 'Hello World', }; @@ -185,8 +185,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); assert.strictEqual(snapshot.attr('title'), 'Hello World', 'snapshot title is correct'); post.set('title', 'Tomster'); @@ -205,8 +205,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); assert.expectAssertion( () => { snapshot.attr('unknown'); @@ -228,10 +228,10 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); - let attributes = snapshot.attributes(); + const attributes = snapshot.attributes(); assert.deepEqual(attributes, { author: undefined, title: 'Hello World' }, 'attributes are returned correctly'); }); @@ -248,11 +248,11 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); post.set('title', 'Hello World!'); - let snapshot = post._createSnapshot(); + const snapshot = post._createSnapshot(); - let changes = snapshot.changedAttributes(); + const changes = snapshot.changedAttributes(); assert.deepEqual(changes.title, ['Hello World', 'Hello World!'], 'changed attributes are returned correctly'); }); @@ -269,9 +269,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let comment = store.peekRecord('comment', 1); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post'); + const comment = store.peekRecord('comment', 1); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post'); assert.strictEqual(relationship, undefined, 'relationship is undefined'); }); @@ -302,9 +302,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let comment = store.peekRecord('comment', 2); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post'); + const comment = store.peekRecord('comment', 2); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post'); assert.strictEqual(relationship, null, 'relationship is unset'); }); @@ -335,9 +335,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let comment = store.peekRecord('comment', 2); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post'); + const comment = store.peekRecord('comment', 2); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post'); assert.ok(relationship instanceof Snapshot, 'snapshot is an instance of Snapshot'); assert.strictEqual(relationship.id, '1', 'post id is correct'); @@ -372,9 +372,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let comment = store.peekRecord('comment', 2); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post'); + const comment = store.peekRecord('comment', 2); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post'); assert.ok(relationship instanceof Snapshot, 'snapshot is an instance of Snapshot'); assert.deepEqual(relationship.changedAttributes(), {}, 'changedAttributes are correct'); @@ -406,13 +406,13 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let post = store.peekRecord('post', 1); - let comment = store.peekRecord('comment', 2); + const post = store.peekRecord('post', 1); + const comment = store.peekRecord('comment', 2); post.deleteRecord(); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post'); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post'); assert.strictEqual(relationship, null, 'relationship unset after deleted'); }); @@ -436,9 +436,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let comment = store.peekRecord('comment', 2); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post'); + const comment = store.peekRecord('comment', 2); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post'); assert.strictEqual(relationship, undefined, 'relationship is undefined'); }); @@ -466,7 +466,7 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let comment = store.peekRecord('comment', 2); + const comment = store.peekRecord('comment', 2); assert.strictEqual(comment._createSnapshot().belongsTo('post'), undefined, 'relationship is undefined'); await comment.post; @@ -485,8 +485,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); assert.expectAssertion( () => { @@ -520,7 +520,7 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let comment = store.peekRecord('comment', '2'); + const comment = store.peekRecord('comment', '2'); const post = await comment.post; store.push({ @@ -545,11 +545,11 @@ module('integration/snapshot - Snapshot', function (hooks) { const comments = await post.comments; comments.push(comment); - let postSnapshot = post._createSnapshot(); - let commentSnapshot = comment._createSnapshot(); + const postSnapshot = post._createSnapshot(); + const commentSnapshot = comment._createSnapshot(); - let hasManyRelationship = postSnapshot.hasMany('comments'); - let belongsToRelationship = commentSnapshot.belongsTo('post'); + const hasManyRelationship = postSnapshot.hasMany('comments'); + const belongsToRelationship = commentSnapshot.belongsTo('post'); assert.ok(hasManyRelationship instanceof Array, 'hasMany relationship is an instance of Array'); assert.strictEqual(hasManyRelationship.length, 1, 'hasMany relationship contains related object'); @@ -583,17 +583,17 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let post = store.peekRecord('post', '1'); - let comment = store.peekRecord('comment', '2'); + const post = store.peekRecord('post', '1'); + const comment = store.peekRecord('comment', '2'); const comments = await post.comments; comments.push(comment); - let postSnapshot = post._createSnapshot(); - let commentSnapshot = comment._createSnapshot(); + const postSnapshot = post._createSnapshot(); + const commentSnapshot = comment._createSnapshot(); - let hasManyRelationship = postSnapshot.hasMany('comments'); - let belongsToRelationship = commentSnapshot.belongsTo('post'); + const hasManyRelationship = postSnapshot.hasMany('comments'); + const belongsToRelationship = commentSnapshot.belongsTo('post'); assert.ok(hasManyRelationship instanceof Array, 'hasMany relationship is an instance of Array'); assert.strictEqual(hasManyRelationship.length, 1, 'hasMany relationship contains related object'); @@ -627,16 +627,16 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let post = store.peekRecord('post', 1); - let comment = store.peekRecord('comment', 2); + const post = store.peekRecord('post', 1); + const comment = store.peekRecord('comment', 2); comment.set('post', post); - let postSnapshot = post._createSnapshot(); - let commentSnapshot = comment._createSnapshot(); + const postSnapshot = post._createSnapshot(); + const commentSnapshot = comment._createSnapshot(); - let hasManyRelationship = postSnapshot.hasMany('comments'); - let belongsToRelationship = commentSnapshot.belongsTo('post'); + const hasManyRelationship = postSnapshot.hasMany('comments'); + const belongsToRelationship = commentSnapshot.belongsTo('post'); assert.ok(hasManyRelationship instanceof Array, 'hasMany relationship is an instance of Array'); assert.strictEqual(hasManyRelationship.length, 1, 'hasMany relationship contains related object'); @@ -675,9 +675,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let comment = store.peekRecord('comment', 2); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post', { id: true }); + const comment = store.peekRecord('comment', 2); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post', { id: true }); assert.strictEqual(relationship, '1', 'relationship ID correctly returned'); }); @@ -708,13 +708,13 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let post = store.peekRecord('post', 1); - let comment = store.peekRecord('comment', 2); + const post = store.peekRecord('post', 1); + const comment = store.peekRecord('comment', 2); post.deleteRecord(); - let snapshot = comment._createSnapshot(); - let relationship = snapshot.belongsTo('post', { id: true }); + const snapshot = comment._createSnapshot(); + const relationship = snapshot.belongsTo('post', { id: true }); assert.strictEqual(relationship, null, 'relationship unset after deleted'); }); @@ -731,9 +731,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments'); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments'); assert.strictEqual(relationship, undefined, 'relationship is undefined'); }); @@ -755,9 +755,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments'); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.strictEqual(relationship.length, 0, 'relationship is empty'); @@ -799,14 +799,14 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let post = store.peekRecord('post', 3); - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments'); + const post = store.peekRecord('post', 3); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.strictEqual(relationship.length, 2, 'relationship has two items'); - let relationship1 = relationship[0]; + const relationship1 = relationship[0]; assert.ok(relationship1 instanceof Snapshot, 'relationship item is an instance of Snapshot'); assert.strictEqual(relationship1.id, '1', 'relationship item id is correct'); @@ -849,15 +849,15 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let comment1 = store.peekRecord('comment', 1); - let comment2 = store.peekRecord('comment', 2); - let post = store.peekRecord('post', 3); + const comment1 = store.peekRecord('comment', 1); + const comment2 = store.peekRecord('comment', 2); + const post = store.peekRecord('post', 3); comment1.deleteRecord(); comment2.deleteRecord(); - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments'); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.strictEqual(relationship.length, 0, 'relationship is empty'); @@ -883,9 +883,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments', { ids: true }); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments', { ids: true }); assert.deepEqual(relationship, ['2', '3'], 'relationship IDs correctly returned'); }); @@ -926,15 +926,15 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let comment1 = store.peekRecord('comment', 1); - let comment2 = store.peekRecord('comment', 2); - let post = store.peekRecord('post', 3); + const comment1 = store.peekRecord('comment', 1); + const comment2 = store.peekRecord('comment', 2); + const post = store.peekRecord('post', 3); comment1.deleteRecord(); comment2.deleteRecord(); - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments', { ids: true }); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments', { ids: true }); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.strictEqual(relationship.length, 0, 'relationship is empty'); @@ -959,9 +959,9 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments'); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments'); assert.strictEqual(relationship, undefined, 'relationship is undefined'); }); @@ -992,11 +992,11 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); await post.comments.then((comments) => { - let snapshot = post._createSnapshot(); - let relationship = snapshot.hasMany('comments'); + const snapshot = post._createSnapshot(); + const relationship = snapshot.hasMany('comments'); assert.ok(relationship instanceof Array, 'relationship is an instance of Array'); assert.strictEqual(relationship.length, 1, 'relationship has one item'); @@ -1015,8 +1015,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); assert.expectAssertion( () => { @@ -1165,10 +1165,10 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); - let attributes = []; + const attributes = []; snapshot.eachAttribute((name) => attributes.push(name)); assert.deepEqual(attributes, ['author', 'title'], 'attributes are iterated correctly'); }); @@ -1176,8 +1176,8 @@ module('integration/snapshot - Snapshot', function (hooks) { test('snapshot.eachRelationship() proxies to record', function (assert) { assert.expect(2); - let getRelationships = function (snapshot) { - let relationships = []; + const getRelationships = function (snapshot) { + const relationships = []; snapshot.eachRelationship((name) => relationships.push(name)); return relationships; }; @@ -1200,8 +1200,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, ], }); - let comment = store.peekRecord('comment', 1); - let post = store.peekRecord('post', 2); + const comment = store.peekRecord('comment', 1); + const post = store.peekRecord('post', 2); let snapshot; snapshot = comment._createSnapshot(); @@ -1232,8 +1232,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let comment = store.peekRecord('comment', 1); - let snapshot = comment._createSnapshot(); + const comment = store.peekRecord('comment', 1); + const snapshot = comment._createSnapshot(); snapshot.belongsTo('post'); }); @@ -1262,8 +1262,8 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); snapshot.hasMany('comments'); }); @@ -1280,12 +1280,12 @@ module('integration/snapshot - Snapshot', function (hooks) { }, }, }); - let post = store.peekRecord('post', 1); - let snapshot = post._createSnapshot(); + const post = store.peekRecord('post', 1); + const snapshot = post._createSnapshot(); post.set('title', 'New Title'); - let expected = { + const expected = { data: { attributes: { author: undefined, diff --git a/tests/main/tests/integration/store-extension-test.ts b/tests/main/tests/integration/store-extension-test.ts index 5c21c9c5d9a..b939191c224 100644 --- a/tests/main/tests/integration/store-extension-test.ts +++ b/tests/main/tests/integration/store-extension-test.ts @@ -1,8 +1,11 @@ -import RequestManager from '@ember-data/request'; import { inject as service } from '@ember/service'; + +import { module, test } from 'qunit'; + import Store from 'ember-data/store'; import { setupTest } from 'ember-qunit'; -import { module, test } from 'qunit'; + +import RequestManager from '@ember-data/request'; module('Integration | Store Extension', function (hooks) { setupTest(hooks); diff --git a/tests/main/tests/integration/store-test.js b/tests/main/tests/integration/store-test.js index 3b0ccee6331..3351f125baf 100644 --- a/tests/main/tests/integration/store-test.js +++ b/tests/main/tests/integration/store-test.js @@ -39,12 +39,12 @@ function ajaxResponse(value) { } function tap(obj, methodName, callback) { - let old = obj[methodName]; + const old = obj[methodName]; - let summary = { called: [] }; + const summary = { called: [] }; obj[methodName] = function () { - let result = old.apply(obj, arguments); + const result = old.apply(obj, arguments); if (callback) { callback.apply(obj, arguments); } @@ -69,9 +69,9 @@ module('integration/store - destroy', function (hooks) { test("destroying record during find doesn't cause unexpected error (find resolves)", async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let TestAdapter = Adapter.extend({ + const TestAdapter = Adapter.extend({ findRecord(store, type, id, snapshot) { return new Promise((resolve, reject) => { store.unloadAll(type.modelName); @@ -88,8 +88,8 @@ module('integration/store - destroy', function (hooks) { this.owner.register('adapter:application', TestAdapter); - let type = 'car'; - let id = '1'; + const type = 'car'; + const id = '1'; try { await store.findRecord(type, id); @@ -102,9 +102,9 @@ module('integration/store - destroy', function (hooks) { test("destroying record during find doesn't cause unexpected error (find rejects)", async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let TestAdapter = Adapter.extend({ + const TestAdapter = Adapter.extend({ findRecord(store, type, id, snapshot) { return new Promise((resolve, reject) => { store.unloadAll(type.modelName); @@ -115,8 +115,8 @@ module('integration/store - destroy', function (hooks) { this.owner.register('adapter:application', TestAdapter); - let type = 'car'; - let id = '1'; + const type = 'car'; + const id = '1'; try { await store.findRecord(type, id); @@ -178,9 +178,8 @@ module('integration/store - destroy', function (hooks) { }); test('destroying the store correctly cleans everything up', async function (assert) { - let car, person; - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -214,11 +213,11 @@ module('integration/store - destroy', function (hooks) { ], }); - car = store.peekRecord('car', '1'); - person = store.peekRecord('person', '1'); + const car = store.peekRecord('car', '1'); + const person = store.peekRecord('person', '1'); - let personWillDestroy = tap(person, 'willDestroy'); - let carWillDestroy = tap(car, 'willDestroy'); + const personWillDestroy = tap(person, 'willDestroy'); + const carWillDestroy = tap(car, 'willDestroy'); const cars = car.person.cars; adapter.query = function () { @@ -233,7 +232,7 @@ module('integration/store - destroy', function (hooks) { }; }; - let adapterPopulatedPeople = await store.query('person', { + const adapterPopulatedPeople = await store.query('person', { someCrazy: 'query', }); @@ -275,7 +274,7 @@ module('integration/store - findRecord', function (hooks) { test('store#findRecord fetches record from server when cached record is not present', async function (assert) { assert.expect(2); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); adapter.ajax = ajaxResponse({ cars: [ @@ -287,11 +286,11 @@ module('integration/store - findRecord', function (hooks) { ], }); - let cachedRecordIsPresent = store.peekRecord('car', '20') !== null; + const cachedRecordIsPresent = store.peekRecord('car', '20') !== null; assert.notOk(cachedRecordIsPresent, 'Car with id=20 should not exist'); - let car = await store.findRecord('car', '20'); + const car = await store.findRecord('car', '20'); assert.strictEqual(car.make, 'BMC', 'Car with id=20 is now loaded'); }); @@ -299,7 +298,7 @@ module('integration/store - findRecord', function (hooks) { test('store#findRecord returns cached record immediately and reloads record in the background', async function (assert) { assert.expect(2); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); adapter.shouldReloadRecord = () => false; adapter.shouldBackgroundReloadRecord = () => true; @@ -316,7 +315,7 @@ module('integration/store - findRecord', function (hooks) { }); let resolver; - let promise = new Promise((r) => (resolver = r)); + const promise = new Promise((r) => (resolver = r)); adapter.ajax = async () => { await promise; @@ -345,7 +344,7 @@ module('integration/store - findRecord', function (hooks) { assert.expect(6); this.owner.unregister('serializer:application'); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); let calls = 0; delete adapter.shouldReloadRecord; @@ -396,7 +395,7 @@ module('integration/store - findRecord', function (hooks) { assert.expect(8); this.owner.unregister('serializer:application'); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); let calls = 0; delete adapter.shouldReloadRecord; @@ -461,7 +460,7 @@ module('integration/store - findRecord', function (hooks) { this.owner.register('adapter:application', testAdapter); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); store.push({ data: { @@ -484,11 +483,11 @@ module('integration/store - findRecord', function (hooks) { ], }); - let cachedCar = store.peekRecord('car', '1'); + const cachedCar = store.peekRecord('car', '1'); assert.strictEqual(cachedCar.model, 'Mini', 'cached car has expected model'); - let car = await store.findRecord('car', '1', { reload: true }); + const car = await store.findRecord('car', '1', { reload: true }); assert.strictEqual(car.model, 'Princess', 'cached record ignored, record reloaded via server'); }); @@ -539,10 +538,10 @@ module('integration/store - findRecord', function (hooks) { let calls = 0; let resolveHandler; - let deferred = new Promise((resolve) => { + const deferred = new Promise((resolve) => { resolveHandler = resolve; }); - let result = { + const result = { data: { type: 'car', id: '1', @@ -566,14 +565,13 @@ module('integration/store - findRecord', function (hooks) { this.owner.register('adapter:application', TestAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let firstPromise, secondPromise; - firstPromise = store.findRecord('car', '1', { reload: true }); - secondPromise = store.findRecord('car', '1', { reload: true }); + const firstPromise = store.findRecord('car', '1', { reload: true }); + const secondPromise = store.findRecord('car', '1', { reload: true }); resolveHandler(result); - let car1 = await firstPromise; - let car2 = await secondPromise; + const car1 = await firstPromise; + const car2 = await secondPromise; assert.strictEqual(calls, 1, 'We made one call to findRecord'); assert.strictEqual(car1, car2, 'we receive the same car back'); @@ -662,7 +660,7 @@ module('integration/store - findRecord', function (hooks) { this.owner.register('adapter:application', testAdapter); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); store.push({ data: { @@ -676,7 +674,7 @@ module('integration/store - findRecord', function (hooks) { }); let resolver; - let promise = new Promise((r) => (resolver = r)); + const promise = new Promise((r) => (resolver = r)); adapter.ajax = async function () { await promise; @@ -691,7 +689,7 @@ module('integration/store - findRecord', function (hooks) { }); }; - let carPromise = await store.findRecord('car', '1', { backgroundReload: true }); + const carPromise = await store.findRecord('car', '1', { backgroundReload: true }); assert.strictEqual(carPromise.model, 'Mini', 'cached car record is returned'); @@ -699,7 +697,7 @@ module('integration/store - findRecord', function (hooks) { resolver(); await settled(); - let car = store.peekRecord('car', '1'); + const car = store.peekRecord('car', '1'); assert.strictEqual(car.model, 'Princess', 'car record was reloaded'); }); @@ -719,7 +717,7 @@ module('integration/store - findRecord', function (hooks) { this.owner.register('adapter:application', testAdapter); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); store.push({ data: { @@ -781,8 +779,8 @@ module('integration/store - findAll', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.ajax = () => { return Promise.resolve({ @@ -817,8 +815,8 @@ module('integration/store - findAll', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.push({ data: { @@ -874,7 +872,7 @@ module('integration/store - findAll', function (hooks) { assert.strictEqual(cars.length, 2, 'There is 2 cars in the store now'); - let mini = cars.find((car) => car.id === '1'); + const mini = cars.find((car) => car.id === '1'); assert.strictEqual(mini.model, 'New Mini', 'Existing records have been updated'); }); @@ -882,7 +880,7 @@ module('integration/store - findAll', function (hooks) { test('store#findAll { backgroundReload: false } skips shouldBackgroundReloadAll, returns cached records & does not reload in the background', async function (assert) { assert.expect(4); - let testAdapter = RESTAdapter.extend({ + const testAdapter = RESTAdapter.extend({ shouldBackgroundReloadAll() { assert.ok(false, 'shouldBackgroundReloadAll should not be called when { backgroundReload: false }'); }, @@ -896,7 +894,7 @@ module('integration/store - findAll', function (hooks) { this.owner.register('serializer:application', RESTSerializer.extend()); this.owner.register('adapter:application', testAdapter); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -925,7 +923,7 @@ module('integration/store - findAll', function (hooks) { test('store#findAll { backgroundReload: true } skips shouldBackgroundReloadAll, returns cached records, & reloads in background', async function (assert) { assert.expect(5); - let testAdapter = RESTAdapter.extend({ + const testAdapter = RESTAdapter.extend({ shouldBackgroundReloadAll() { assert.ok(false, 'shouldBackgroundReloadAll should not be called when { backgroundReload: true }'); }, @@ -935,8 +933,8 @@ module('integration/store - findAll', function (hooks) { this.owner.register('model:car', Car); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.push({ data: { @@ -950,7 +948,7 @@ module('integration/store - findAll', function (hooks) { }); let resolve; - let promise = new Promise((r) => { + const promise = new Promise((r) => { resolve = r; }); adapter.ajax = async () => { @@ -990,7 +988,7 @@ module('integration/store - findAll', function (hooks) { test('store#findAll { backgroundReload: false } is ignored if adapter.shouldReloadAll is true', async function (assert) { assert.expect(5); - let testAdapter = RESTAdapter.extend({ + const testAdapter = RESTAdapter.extend({ shouldReloadAll() { return true; }, @@ -1004,8 +1002,8 @@ module('integration/store - findAll', function (hooks) { this.owner.register('adapter:application', testAdapter); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.push({ data: { @@ -1054,8 +1052,8 @@ module('integration/store - findAll', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); store.push({ data: [ @@ -1100,7 +1098,7 @@ module('integration/store - findAll', function (hooks) { return resolvefindAllPromise; }; - let cars = await store.findAll('car'); + const cars = await store.findAll('car'); assert.strictEqual(cars.length, 2, 'It returns all cars'); @@ -1127,8 +1125,8 @@ module('integration/store - findAll', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.ajax = () => { return Promise.resolve({ @@ -1159,7 +1157,7 @@ module('integration/store - findAll', function (hooks) { assert.strictEqual(store.peekRecord('car', '20'), null, 'the car is not loaded'); - let car = await store.findRecord('car', '20'); + const car = await store.findRecord('car', '20'); assert.strictEqual(car.make, 'BMCW', 'Car with id=20 is now loaded'); }); @@ -1171,10 +1169,10 @@ module('integration/store - findAll', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); try { - let applicationAdapter = store.adapterFor('application'); + const applicationAdapter = store.adapterFor('application'); assert.ok(applicationAdapter); } catch (_error) { @@ -1189,10 +1187,10 @@ module('integration/store - findAll', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); try { - let applicationSerializer = store.serializerFor('application'); + const applicationSerializer = store.serializerFor('application'); assert.ok(applicationSerializer); } catch (_error) { @@ -1211,8 +1209,7 @@ module('integration/store - deleteRecord', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let person; + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -1224,7 +1221,7 @@ module('integration/store - deleteRecord', function (hooks) { }, }); - person = store.peekRecord('person', '1'); + const person = store.peekRecord('person', '1'); assert.notStrictEqual(store.peekRecord('person', '1'), null, 'expected the record to be in the store'); @@ -1238,7 +1235,7 @@ module('integration/store - deleteRecord', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); try { store.push({ data: null }); @@ -1258,7 +1255,7 @@ module('integration/store - deleteRecord', function (hooks) { this.owner.register('serializer:application', class extends JSONAPISerializer {}); this.owner.register('model:car', Car); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async () => { await store.findRecord('car', '1'); @@ -1270,14 +1267,14 @@ module('integration/store - deleteRecord', function (hooks) { this.owner.register('adapter:application', RESTAdapter.extend()); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function () { return {}; }; - let car = store.createRecord('car'); + const car = store.createRecord('car'); await assert.expectAssertion(async () => { await car.save(); @@ -1297,9 +1294,9 @@ module('integration/store - queryRecord', function (hooks) { testInDebug( 'store#queryRecord should assert when normalized payload of adapter has an array of data', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); - let serializer = store.serializerFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); + const serializer = store.serializerFor('application'); adapter.queryRecord = function () { return { @@ -1322,8 +1319,8 @@ module('integration/store - queryRecord', function (hooks) { test('The store should trap exceptions that are thrown from adapter#findRecord', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function () { throw new Error('Refusing to find record'); @@ -1339,8 +1336,8 @@ module('integration/store - queryRecord', function (hooks) { test('The store should trap exceptions that are thrown from adapter#findAll', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findAll = function () { throw new Error('Refusing to find all records'); @@ -1356,8 +1353,8 @@ module('integration/store - queryRecord', function (hooks) { test('The store should trap exceptions that are thrown from adapter#query', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.query = function () { throw new Error('Refusing to query records'); @@ -1373,8 +1370,8 @@ module('integration/store - queryRecord', function (hooks) { test('The store should trap exceptions that are thrown from adapter#queryRecord', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.queryRecord = function () { throw new Error('Refusing to query record'); @@ -1390,15 +1387,15 @@ module('integration/store - queryRecord', function (hooks) { test('The store should trap exceptions that are thrown from adapter#createRecord', async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.createRecord = function () { throw new Error('Refusing to serialize'); }; try { - let car = store.createRecord('car'); + const car = store.createRecord('car'); await car.save(); } catch (error) { diff --git a/tests/main/tests/integration/store/adapter-for-test.js b/tests/main/tests/integration/store/adapter-for-test.js index 20cd99d69fe..efd9587f4e5 100644 --- a/tests/main/tests/integration/store/adapter-for-test.js +++ b/tests/main/tests/integration/store/adapter-for-test.js @@ -23,13 +23,13 @@ module('integration/store - adapterFor', function (hooks) { let store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; store = owner.lookup('service:store'); }); test('when no adapter is available we throw an error', async function (assert) { assert.expectAssertion(() => { - let { owner } = this; + const { owner } = this; /* adapter:-json-api is the "last chance" fallback and is the json-api adapter which is re-exported as app/adapters/-json-api. @@ -50,7 +50,7 @@ module('integration/store - adapterFor', function (hooks) { }); test('we find and instantiate the application adapter', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiate = false; class AppAdapter extends TestAdapter { @@ -61,13 +61,13 @@ module('integration/store - adapterFor', function (hooks) { owner.register('adapter:application', AppAdapter); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); assert.ok(adapter instanceof AppAdapter, 'We found the correct adapter'); assert.ok(didInstantiate, 'We instantiated the adapter'); didInstantiate = false; - let adapterAgain = store.adapterFor('application'); + const adapterAgain = store.adapterFor('application'); assert.ok(adapterAgain instanceof AppAdapter, 'We found the correct adapter'); assert.notOk(didInstantiate, 'We did not instantiate the adapter again'); @@ -75,7 +75,7 @@ module('integration/store - adapterFor', function (hooks) { }); test('multiple stores do not share adapters', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiate = false; class AppAdapter extends TestAdapter { @@ -87,14 +87,14 @@ module('integration/store - adapterFor', function (hooks) { owner.register('adapter:application', AppAdapter); owner.register('service:other-store', Store); - let otherStore = owner.lookup('service:other-store'); - let adapter = store.adapterFor('application'); + const otherStore = owner.lookup('service:other-store'); + const adapter = store.adapterFor('application'); assert.ok(adapter instanceof AppAdapter, 'We found the correct adapter'); assert.ok(didInstantiate, 'We instantiated the adapter'); didInstantiate = false; - let otherAdapter = otherStore.adapterFor('application'); + const otherAdapter = otherStore.adapterFor('application'); assert.ok(otherAdapter instanceof AppAdapter, 'We found the correct adapter again'); assert.ok(didInstantiate, 'We instantiated the other adapter'); assert.notStrictEqual(otherAdapter, adapter, 'We have a different adapter instance'); @@ -103,7 +103,7 @@ module('integration/store - adapterFor', function (hooks) { }); test('we can find and instantiate per-type adapters', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiateAppAdapter = false; let didInstantiatePersonAdapter = false; @@ -122,20 +122,20 @@ module('integration/store - adapterFor', function (hooks) { owner.register('adapter:application', AppAdapter); owner.register('adapter:person', PersonAdapter); - let adapter = store.adapterFor('person'); + const adapter = store.adapterFor('person'); assert.ok(adapter instanceof PersonAdapter, 'We found the correct adapter'); assert.ok(didInstantiatePersonAdapter, 'We instantiated the person adapter'); assert.notOk(didInstantiateAppAdapter, 'We did not instantiate the application adapter'); - let appAdapter = store.adapterFor('application'); + const appAdapter = store.adapterFor('application'); assert.ok(appAdapter instanceof AppAdapter, 'We found the correct adapter'); assert.ok(didInstantiateAppAdapter, 'We instantiated the application adapter'); assert.notStrictEqual(appAdapter, adapter, 'We have separate adapters'); }); test('we fallback to the application adapter when a per-type adapter is not found', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiateAppAdapter = false; class AppAdapter extends TestAdapter { @@ -146,20 +146,20 @@ module('integration/store - adapterFor', function (hooks) { owner.register('adapter:application', AppAdapter); - let adapter = store.adapterFor('person'); + const adapter = store.adapterFor('person'); assert.ok(adapter instanceof AppAdapter, 'We found the adapter'); assert.ok(didInstantiateAppAdapter, 'We instantiated the adapter'); didInstantiateAppAdapter = false; - let appAdapter = store.adapterFor('application'); + const appAdapter = store.adapterFor('application'); assert.ok(appAdapter instanceof AppAdapter, 'We found the correct adapter'); assert.notOk(didInstantiateAppAdapter, 'We did not instantiate the adapter again'); assert.strictEqual(appAdapter, adapter, 'We fell back to the application adapter instance'); }); test('adapters are destroyed', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiate = false; let didDestroy = false; @@ -175,7 +175,7 @@ module('integration/store - adapterFor', function (hooks) { owner.register('adapter:application', AppAdapter); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); assert.ok(adapter instanceof AppAdapter, 'precond - We found the correct adapter'); assert.ok(didInstantiate, 'precond - We instantiated the adapter'); diff --git a/tests/main/tests/integration/store/json-api-validation-test.js b/tests/main/tests/integration/store/json-api-validation-test.js index b32a9cd3bbb..ac8041e5d78 100644 --- a/tests/main/tests/integration/store/json-api-validation-test.js +++ b/tests/main/tests/integration/store/json-api-validation-test.js @@ -68,7 +68,7 @@ module('integration/store/json-validation', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async function () { await store.findRecord('person', '1'); @@ -94,7 +94,7 @@ module('integration/store/json-validation', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async function () { await store.findRecord('person', '1'); @@ -120,7 +120,7 @@ module('integration/store/json-validation', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async function () { await store.findRecord('person', '1'); @@ -151,7 +151,7 @@ module('integration/store/json-validation', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async function () { await store.findRecord('person', '1'); diff --git a/tests/main/tests/integration/store/package-import-test.js b/tests/main/tests/integration/store/package-import-test.js index 47b932ac0c5..11820b7de7f 100644 --- a/tests/main/tests/integration/store/package-import-test.js +++ b/tests/main/tests/integration/store/package-import-test.js @@ -18,7 +18,7 @@ module('integration/store/package-import', function (hooks) { let store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:person', Person); owner.unregister('service:store'); @@ -45,7 +45,7 @@ module('integration/store/package-import', function (hooks) { ], }); - let all = store.peekAll('person'); + const all = store.peekAll('person'); assert.strictEqual(get(all, 'length'), 2); store.push({ diff --git a/tests/main/tests/integration/store/query-record-test.js b/tests/main/tests/integration/store/query-record-test.js index f06e1062fa9..a7159280f1e 100644 --- a/tests/main/tests/integration/store/query-record-test.js +++ b/tests/main/tests/integration/store/query-record-test.js @@ -20,7 +20,7 @@ module('integration/store/query-record - Query one record with a query hash', fu }); testInDebug('It raises an assertion when no type is passed', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async function () { await store.queryRecord(); @@ -28,7 +28,7 @@ module('integration/store/query-record - Query one record with a query hash', fu }); testInDebug('It raises an assertion when no query hash is passed', async function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectAssertion(async function () { await store.queryRecord('person'); @@ -38,8 +38,8 @@ module('integration/store/query-record - Query one record with a query hash', fu test("When a record is requested, the adapter's queryRecord method should be called.", async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let Person = store.modelFor('person'); + const store = this.owner.lookup('service:store'); + const Person = store.modelFor('person'); this.owner.register( 'adapter:person', @@ -68,7 +68,7 @@ module('integration/store/query-record - Query one record with a query hash', fu }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.queryRecord('person', {}).catch(function (reason) { assert.ok(true, 'The rejection handler was called'); @@ -109,7 +109,7 @@ module('integration/store/query-record - Query one record with a query hash', fu }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.queryRecord('person', { related: 'posts' }); }); diff --git a/tests/main/tests/integration/store/serializer-for-test.js b/tests/main/tests/integration/store/serializer-for-test.js index 77ba0bd39d2..a904ca77266 100644 --- a/tests/main/tests/integration/store/serializer-for-test.js +++ b/tests/main/tests/integration/store/serializer-for-test.js @@ -36,13 +36,13 @@ module('integration/store - serializerFor', function (hooks) { let store; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; store = owner.lookup('service:store'); }); test('when no serializer is available we return null', async function (assert) { - let { owner } = this; + const { owner } = this; /* serializer:-default is the "last chance" fallback and is the json-api serializer which is re-exported as app/serializers/-default. @@ -62,7 +62,7 @@ module('integration/store - serializerFor', function (hooks) { }); test('we find and instantiate the application serializer', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiate = false; class AppSerializer extends TestSerializer { @@ -73,13 +73,13 @@ module('integration/store - serializerFor', function (hooks) { owner.register('serializer:application', AppSerializer); - let serializer = store.serializerFor('application'); + const serializer = store.serializerFor('application'); assert.ok(serializer instanceof AppSerializer, 'We found the correct serializer'); assert.ok(didInstantiate, 'We instantiated the serializer'); didInstantiate = false; - let serializerAgain = store.serializerFor('application'); + const serializerAgain = store.serializerFor('application'); assert.ok(serializerAgain instanceof AppSerializer, 'We found the correct serializer'); assert.notOk(didInstantiate, 'We did not instantiate the serializer again'); @@ -87,7 +87,7 @@ module('integration/store - serializerFor', function (hooks) { }); test('multiple stores do not share serializers', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiate = false; class AppSerializer extends TestSerializer { @@ -99,14 +99,14 @@ module('integration/store - serializerFor', function (hooks) { owner.register('serializer:application', AppSerializer); owner.register('service:other-store', Store); - let otherStore = owner.lookup('service:other-store'); - let serializer = store.serializerFor('application'); + const otherStore = owner.lookup('service:other-store'); + const serializer = store.serializerFor('application'); assert.ok(serializer instanceof AppSerializer, 'We found the correct serializer'); assert.ok(didInstantiate, 'We instantiated the serializer'); didInstantiate = false; - let otherSerializer = otherStore.serializerFor('application'); + const otherSerializer = otherStore.serializerFor('application'); assert.ok(otherSerializer instanceof AppSerializer, 'We found the correct serializer again'); assert.ok(didInstantiate, 'We instantiated the other serializer'); assert.notStrictEqual(otherSerializer, serializer, 'We have a different serializer instance'); @@ -115,7 +115,7 @@ module('integration/store - serializerFor', function (hooks) { }); test('we can find and instantiate per-type serializers', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiateAppSerializer = false; let didInstantiatePersonSerializer = false; @@ -134,20 +134,20 @@ module('integration/store - serializerFor', function (hooks) { owner.register('serializer:application', AppSerializer); owner.register('serializer:person', PersonSerializer); - let serializer = store.serializerFor('person'); + const serializer = store.serializerFor('person'); assert.ok(serializer instanceof PersonSerializer, 'We found the correct serializer'); assert.ok(didInstantiatePersonSerializer, 'We instantiated the person serializer'); assert.notOk(didInstantiateAppSerializer, 'We did not instantiate the application serializer'); - let appSerializer = store.serializerFor('application'); + const appSerializer = store.serializerFor('application'); assert.ok(appSerializer instanceof AppSerializer, 'We found the correct serializer'); assert.ok(didInstantiateAppSerializer, 'We instantiated the application serializer'); assert.notStrictEqual(appSerializer, serializer, 'We have separate serializers'); }); test('we fallback to the application serializer when a per-type serializer is not found', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiateAppSerializer = false; class AppSerializer extends TestSerializer { @@ -158,20 +158,20 @@ module('integration/store - serializerFor', function (hooks) { owner.register('serializer:application', AppSerializer); - let serializer = store.serializerFor('person'); + const serializer = store.serializerFor('person'); assert.ok(serializer instanceof AppSerializer, 'We found the serializer'); assert.ok(didInstantiateAppSerializer, 'We instantiated the serializer'); didInstantiateAppSerializer = false; - let appSerializer = store.serializerFor('application'); + const appSerializer = store.serializerFor('application'); assert.ok(appSerializer instanceof AppSerializer, 'We found the correct serializer'); assert.notOk(didInstantiateAppSerializer, 'We did not instantiate the serializer again'); assert.strictEqual(appSerializer, serializer, 'We fell back to the application serializer instance'); }); test('serializers are destroyed', async function (assert) { - let { owner } = this; + const { owner } = this; let didInstantiate = false; let didDestroy = false; @@ -187,7 +187,7 @@ module('integration/store - serializerFor', function (hooks) { owner.register('serializer:application', AppSerializer); - let serializer = store.serializerFor('application'); + const serializer = store.serializerFor('application'); assert.ok(serializer instanceof AppSerializer, 'precond - We found the correct serializer'); assert.ok(didInstantiate, 'precond - We instantiated the serializer'); diff --git a/tests/main/tests/integration/store/store-creation-recursion-test.js b/tests/main/tests/integration/store/store-creation-recursion-test.js index 2fe05764f8d..5d32a15774b 100644 --- a/tests/main/tests/integration/store/store-creation-recursion-test.js +++ b/tests/main/tests/integration/store/store-creation-recursion-test.js @@ -8,12 +8,12 @@ module('integration/store/creation-recursion', function (hooks) { setupTest(hooks); test('store construction does not construct transforms', function (assert) { - let storeFactory = this.owner.factoryFor('service:store'); + const storeFactory = this.owner.factoryFor('service:store'); this.owner.unregister('service:store'); this.owner.register('service:store', storeFactory.class); - let test = this; + const test = this; test.dateTransformCreated = false; class MockDateTransform extends Transform { constructor(...args) { diff --git a/tests/main/tests/test-helper.js b/tests/main/tests/test-helper.js index c4f2f7bc918..a5e9252a732 100644 --- a/tests/main/tests/test-helper.js +++ b/tests/main/tests/test-helper.js @@ -3,13 +3,13 @@ import { _backburner } from '@ember/runloop'; import { getSettledState, isSettled, registerHook, setApplication } from '@ember/test-helpers'; import { getPendingWaiterState } from '@ember/test-waiters'; -import { setTestId } from '@warp-drive/holodeck'; import * as QUnit from 'qunit'; import { setup } from 'qunit-dom'; import start from 'ember-exam/test-support/start'; import configureAsserts from '@ember-data/unpublished-test-infra/test-support/asserts'; +import { setTestId } from '@warp-drive/holodeck'; import Application from '../app'; import config from '../config/environment'; diff --git a/tests/main/tests/unit/adapter-errors-test.js b/tests/main/tests/unit/adapter-errors-test.js index cd5d9916b70..721814ad482 100644 --- a/tests/main/tests/unit/adapter-errors-test.js +++ b/tests/main/tests/unit/adapter-errors-test.js @@ -14,7 +14,7 @@ import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in module('unit/adapter-errors - AdapterError', function () { test('AdapterError', function (assert) { - let error = new AdapterError(); + const error = new AdapterError(); assert.ok(error instanceof Error); assert.ok(error.isAdapterError); @@ -22,7 +22,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('InvalidError', function (assert) { - let error = new InvalidError(); + const error = new InvalidError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -31,7 +31,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('TimeoutError', function (assert) { - let error = new TimeoutError(); + const error = new TimeoutError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -40,7 +40,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('AbortError', function (assert) { - let error = new AbortError(); + const error = new AbortError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -49,7 +49,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('UnauthorizedError', function (assert) { - let error = new UnauthorizedError(); + const error = new UnauthorizedError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -58,7 +58,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('ForbiddenError', function (assert) { - let error = new ForbiddenError(); + const error = new ForbiddenError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -67,7 +67,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('NotFoundError', function (assert) { - let error = new NotFoundError(); + const error = new NotFoundError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -76,7 +76,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('ConflictError', function (assert) { - let error = new ConflictError(); + const error = new ConflictError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -85,7 +85,7 @@ module('unit/adapter-errors - AdapterError', function () { }); test('ServerError', function (assert) { - let error = new ServerError(); + const error = new ServerError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -94,8 +94,8 @@ module('unit/adapter-errors - AdapterError', function () { }); test('CustomAdapterError', function (assert) { - let CustomAdapterError = AdapterError.extend(); - let error = new CustomAdapterError(); + const CustomAdapterError = AdapterError.extend(); + const error = new CustomAdapterError(); assert.ok(error instanceof Error); assert.ok(error instanceof AdapterError); @@ -104,8 +104,8 @@ module('unit/adapter-errors - AdapterError', function () { }); test('CustomAdapterError with default message', function (assert) { - let CustomAdapterError = AdapterError.extend({ message: 'custom error!' }); - let error = new CustomAdapterError(); + const CustomAdapterError = AdapterError.extend({ message: 'custom error!' }); + const error = new CustomAdapterError(); assert.strictEqual(error.message, 'custom error!'); }); diff --git a/tests/main/tests/unit/adapters/build-url-mixin/build-url-test.js b/tests/main/tests/unit/adapters/build-url-mixin/build-url-test.js index 0ad714ff4c0..a4cc99366c3 100644 --- a/tests/main/tests/unit/adapters/build-url-mixin/build-url-test.js +++ b/tests/main/tests/unit/adapters/build-url-mixin/build-url-test.js @@ -28,8 +28,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - find requestType delegates to urlForFindRecord', function (assert) { assert.expect(4); - let snapshotStub = { snapshot: true }; - let originalMethod = adapter.urlForFindRecord; + const snapshotStub = { snapshot: true }; + const originalMethod = adapter.urlForFindRecord; adapter.urlForFindRecord = function (id, type, snapshot) { assert.strictEqual(id, 1); assert.strictEqual(type, 'super-user'); @@ -41,8 +41,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - findAll requestType delegates to urlForFindAll', function (assert) { assert.expect(3); - let originalMethod = adapter.urlForFindAll; - let snapshotStub = { snapshot: true }; + const originalMethod = adapter.urlForFindAll; + const snapshotStub = { snapshot: true }; adapter.urlForFindAll = function (type, snapshot) { assert.strictEqual(type, 'super-user'); assert.strictEqual(snapshot, snapshotStub); @@ -53,8 +53,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - query requestType delegates to urlForQuery', function (assert) { assert.expect(3); - let originalMethod = adapter.urlForQuery; - let queryStub = { limit: 10 }; + const originalMethod = adapter.urlForQuery; + const queryStub = { limit: 10 }; adapter.urlForQuery = function (query, type) { assert.strictEqual(query, queryStub); assert.strictEqual(type, 'super-user'); @@ -65,8 +65,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - queryRecord requestType delegates to urlForQueryRecord', function (assert) { assert.expect(3); - let originalMethod = adapter.urlForQueryRecord; - let queryStub = { companyId: 10 }; + const originalMethod = adapter.urlForQueryRecord; + const queryStub = { companyId: 10 }; adapter.urlForQueryRecord = function (query, type) { assert.strictEqual(query, queryStub); assert.strictEqual(type, 'super-user'); @@ -77,8 +77,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - findMany requestType delegates to urlForFindMany', function (assert) { assert.expect(3); - let originalMethod = adapter.urlForFindMany; - let idsStub = [1, 2, 3]; + const originalMethod = adapter.urlForFindMany; + const idsStub = [1, 2, 3]; adapter.urlForFindMany = function (ids, type) { assert.strictEqual(ids, idsStub); assert.strictEqual(type, 'super-user'); @@ -89,8 +89,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - findHasMany requestType delegates to urlForFindHasMany', function (assert) { assert.expect(4); - let originalMethod = adapter.urlForFindHasMany; - let snapshotStub = { snapshot: true }; + const originalMethod = adapter.urlForFindHasMany; + const snapshotStub = { snapshot: true }; adapter.urlForFindHasMany = function (id, type, snapshot) { assert.strictEqual(id, 1); assert.strictEqual(type, 'super-user'); @@ -102,8 +102,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - findBelongsTo requestType delegates to urlForFindBelongsTo', function (assert) { assert.expect(4); - let originalMethod = adapter.urlForFindBelongsTo; - let snapshotStub = { snapshot: true }; + const originalMethod = adapter.urlForFindBelongsTo; + const snapshotStub = { snapshot: true }; adapter.urlForFindBelongsTo = function (id, type, snapshot) { assert.strictEqual(id, 1); assert.strictEqual(type, 'super-user'); @@ -115,8 +115,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - createRecord requestType delegates to urlForCreateRecord', function (assert) { assert.expect(3); - let snapshotStub = { snapshot: true }; - let originalMethod = adapter.urlForCreateRecord; + const snapshotStub = { snapshot: true }; + const originalMethod = adapter.urlForCreateRecord; adapter.urlForCreateRecord = function (type, snapshot) { assert.strictEqual(type, 'super-user'); assert.strictEqual(snapshot, snapshotStub); @@ -127,8 +127,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - updateRecord requestType delegates to urlForUpdateRecord', function (assert) { assert.expect(4); - let snapshotStub = { snapshot: true }; - let originalMethod = adapter.urlForUpdateRecord; + const snapshotStub = { snapshot: true }; + const originalMethod = adapter.urlForUpdateRecord; adapter.urlForUpdateRecord = function (id, type, snapshot) { assert.strictEqual(id, 1); assert.strictEqual(type, 'super-user'); @@ -140,8 +140,8 @@ module('unit/adapters/build-url-mixin/build-url - BuildURLMixin#buildURL', funct test('buildURL - deleteRecord requestType delegates to urlForDeleteRecord', function (assert) { assert.expect(4); - let snapshotStub = { snapshot: true }; - let originalMethod = adapter.urlForDeleteRecord; + const snapshotStub = { snapshot: true }; + const originalMethod = adapter.urlForDeleteRecord; adapter.urlForDeleteRecord = function (id, type, snapshot) { assert.strictEqual(id, 1); assert.strictEqual(type, 'super-user'); diff --git a/tests/main/tests/unit/adapters/build-url-mixin/path-for-type-test.js b/tests/main/tests/unit/adapters/build-url-mixin/path-for-type-test.js index cac2b5e00f4..9b245e0a938 100644 --- a/tests/main/tests/unit/adapters/build-url-mixin/path-for-type-test.js +++ b/tests/main/tests/unit/adapters/build-url-mixin/path-for-type-test.js @@ -9,7 +9,7 @@ module('unit/adapters/build-url-mixin/path-for-type - DS.BuildURLMixin#pathForTy hooks.beforeEach(function () { // test for overriden pathForType methods which return null path values - let customPathForType = { + const customPathForType = { pathForType(type) { if (type === 'rootModel') { return ''; @@ -22,17 +22,17 @@ module('unit/adapters/build-url-mixin/path-for-type - DS.BuildURLMixin#pathForTy }); test('pathForType - works with camelized types', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); assert.strictEqual(adapter.pathForType('superUser'), 'superUsers'); }); test('pathForType - works with dasherized types', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); assert.strictEqual(adapter.pathForType('super-user'), 'superUsers'); }); test('pathForType - works with underscored types', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); assert.strictEqual(adapter.pathForType('super_user'), 'superUsers'); }); }); diff --git a/tests/main/tests/unit/adapters/json-api-adapter/ajax-options-test.js b/tests/main/tests/unit/adapters/json-api-adapter/ajax-options-test.js index d0a99b1f497..47d7e60b0ac 100644 --- a/tests/main/tests/unit/adapters/json-api-adapter/ajax-options-test.js +++ b/tests/main/tests/unit/adapters/json-api-adapter/ajax-options-test.js @@ -19,12 +19,12 @@ module('unit/adapters/json-api-adapter/ajax-options - building requests', functi }); test('ajaxOptions() adds Accept when no other headers exist', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); - let url = 'example.com'; - let type = 'GET'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); - let receivedHeaders = ajaxOptions.headers; + const url = 'example.com'; + const type = 'GET'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, @@ -36,14 +36,14 @@ module('unit/adapters/json-api-adapter/ajax-options - building requests', functi }); test('ajaxOptions() adds Accept header to existing headers', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); adapter.headers = { 'Other-key': 'Other Value' }; - let url = 'example.com'; - let type = 'GET'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); - let receivedHeaders = ajaxOptions.headers; + const url = 'example.com'; + const type = 'GET'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, @@ -56,14 +56,14 @@ module('unit/adapters/json-api-adapter/ajax-options - building requests', functi }); test('ajaxOptions() adds Accept header to existing computed properties headers', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); adapter.headers = { 'Other-key': 'Other Value' }; - let url = 'example.com'; - let type = 'GET'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); - let receivedHeaders = ajaxOptions.headers; + const url = 'example.com'; + const type = 'GET'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, @@ -76,14 +76,14 @@ module('unit/adapters/json-api-adapter/ajax-options - building requests', functi }); test('ajaxOptions() does not overwrite passed value of Accept headers', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); adapter.headers = { 'Other-Key': 'Other Value', Accept: 'application/json' }; - let url = 'example.com'; - let type = 'GET'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); - let receivedHeaders = ajaxOptions.headers; + const url = 'example.com'; + const type = 'GET'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, @@ -96,14 +96,14 @@ module('unit/adapters/json-api-adapter/ajax-options - building requests', functi }); test('ajaxOptions() headers are set POST', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); adapter.headers = {}; - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); - let receivedHeaders = ajaxOptions.headers; + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, @@ -116,14 +116,14 @@ module('unit/adapters/json-api-adapter/ajax-options - building requests', functi }); test('ajaxOptions() does not override with existing headers["Content-Type"] POST', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); adapter.headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); - let receivedHeaders = ajaxOptions.headers; + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, @@ -136,17 +136,17 @@ module('unit/adapters/json-api-adapter/ajax-options - building requests', functi }); test('ajaxOptions() can override with options.contentType POST', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); adapter.headers = {}; - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { contentType: 'application/x-www-form-urlencoded', data: { type: 'post' }, }); - let receivedHeaders = ajaxOptions.headers; + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, diff --git a/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js b/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js index 627cb7bf1e3..a39e2aa7b85 100644 --- a/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js +++ b/tests/main/tests/unit/adapters/rest-adapter/ajax-options-test.js @@ -29,8 +29,8 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( test('When an id is searched, the correct url should be generated', async function (assert) { assert.expect(2); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); let count = 0; @@ -52,8 +52,8 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( test(`id's should be sanatized`, async function (assert) { assert.expect(1); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.ajax = function (url, method) { assert.strictEqual(url, '/people/..%2Fplace%2F1', 'should create the correct url'); @@ -64,18 +64,18 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() headers are set', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.headers = { 'Content-Type': 'application/json', 'Other-key': 'Other Value', }; - let url = 'example.com'; - let type = 'GET'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); - let receivedHeaders = ajaxOptions.headers; + const url = 'example.com'; + const type = 'GET'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); + const receivedHeaders = ajaxOptions.headers; assert.deepEqual( receivedHeaders, @@ -88,12 +88,12 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() do not serializes data when GET', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'GET'; - let ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); + const url = 'example.com'; + const type = 'GET'; + const ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); assert.deepEqual(ajaxOptions, { credentials: 'same-origin', @@ -108,12 +108,12 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() serializes data when not GET', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { data: { key: 'value' } }); assert.deepEqual(ajaxOptions, { credentials: 'same-origin', @@ -129,12 +129,12 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() can provide own headers["Content-Type"]', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, @@ -155,12 +155,12 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() can provide own contentType in options', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { contentType: 'application/x-www-form-urlencoded', data: { key: 'value' }, }); @@ -180,12 +180,12 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() empty data', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); assert.deepEqual(ajaxOptions, { credentials: 'same-origin', @@ -197,16 +197,16 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() headers take precedence over adapter headers', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.headers = { 'Content-Type': 'application/x-www-form-urlencoded', }; - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { headers: { 'Content-Type': 'application/json', }, @@ -224,12 +224,12 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('_fetchRequest() returns a promise', async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let noop = function () {}; + const noop = function () {}; - let fetchPlacePromise = adapter._fetchRequest({ + const fetchPlacePromise = adapter._fetchRequest({ url: '/places/1', success: noop, error: noop, @@ -251,57 +251,57 @@ module('unit/adapters/rest-adapter/ajax-options - building requests', function ( }); test('ajaxOptions() Content-Type is not set with ajax GET', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'GET'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); + const url = 'example.com'; + const type = 'GET'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); assert.notOk(ajaxOptions.contentType, 'contentType not set with GET'); }); test('ajaxOptions() Content-Type is not set with ajax POST no data', function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, {}); + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, {}); assert.notOk(ajaxOptions.contentType, 'contentType not set with POST no data'); }); test('ajaxOptions() Content-Type is set with ajax POST with data if not useFetch', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); this.owner.register( 'adapter:application', class extends RESTAdapter { useFetch = false; } ); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); assert.strictEqual(ajaxOptions.contentType, 'application/json; charset=utf-8', 'contentType is set with POST'); }); test('ajaxOptions() Content-Type is set with ajax POST with data if useFetch', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); this.owner.register( 'adapter:application', class extends RESTAdapter { useFetch = true; } ); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); - let url = 'example.com'; - let type = 'POST'; - let ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); + const url = 'example.com'; + const type = 'POST'; + const ajaxOptions = adapter.ajaxOptions(url, type, { data: { type: 'post' } }); assert.strictEqual( ajaxOptions.headers['content-type'], diff --git a/tests/main/tests/unit/adapters/rest-adapter/detailed-message-test.js b/tests/main/tests/unit/adapters/rest-adapter/detailed-message-test.js index cad85fe5071..a130b098722 100644 --- a/tests/main/tests/unit/adapters/rest-adapter/detailed-message-test.js +++ b/tests/main/tests/unit/adapters/rest-adapter/detailed-message-test.js @@ -16,9 +16,9 @@ module('unit/adapters/rest_adapter/detailed_message_test - RESTAdapter#generated test('generating a wonderfully friendly error message should work', function (assert) { assert.expect(1); - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); - let friendlyMessage = adapter.generatedDetailedMessage( + const friendlyMessage = adapter.generatedDetailedMessage( 418, { 'content-type': 'text/plain' }, "I'm a little teapot, short and stout", @@ -39,9 +39,9 @@ module('unit/adapters/rest_adapter/detailed_message_test - RESTAdapter#generated }); test('generating a friendly error message with a missing content-type header should work', function (assert) { - let adapter = this.owner.lookup('adapter:application'); + const adapter = this.owner.lookup('adapter:application'); - let friendlyMessage = adapter.generatedDetailedMessage(418, {}, `I'm a little teapot, short and stout`, { + const friendlyMessage = adapter.generatedDetailedMessage(418, {}, `I'm a little teapot, short and stout`, { url: '/teapots/testing', method: 'GET', }); diff --git a/tests/main/tests/unit/adapters/rest-adapter/fetch-options-test.js b/tests/main/tests/unit/adapters/rest-adapter/fetch-options-test.js index 4c7f0cc2375..500dcdaed18 100644 --- a/tests/main/tests/unit/adapters/rest-adapter/fetch-options-test.js +++ b/tests/main/tests/unit/adapters/rest-adapter/fetch-options-test.js @@ -21,7 +21,7 @@ module('unit/adapters/rest-adapter/fetch-options', function (hooks) { data: dataAsObject, }; - let options = fetchOptions(undefinedQueryStringOptions); + const options = fetchOptions(undefinedQueryStringOptions); assert.deepEqual(options.body, '{"a":1,"c":3,"d":null,"e":0,"f":false}'); }); @@ -60,7 +60,7 @@ module('unit/adapters/rest-adapter/fetch-options', function (hooks) { data: stringifiedData, }; - let options = fetchOptions(optionsWithStringData); + const options = fetchOptions(optionsWithStringData); assert.strictEqual(options.body, stringifiedData); }); @@ -140,7 +140,7 @@ module('unit/adapters/rest-adapter/fetch-options', function (hooks) { test("fetchOptions sets the request body correctly when 'data' is a String", function (assert) { assert.expect(1); - let stringBody = JSON.stringify({ a: 1, b: 2, c: 3 }); + const stringBody = JSON.stringify({ a: 1, b: 2, c: 3 }); const postData = { url: 'https://emberjs.com', method: 'POST', @@ -167,7 +167,7 @@ module('unit/adapters/rest-adapter/fetch-options', function (hooks) { test("fetchOptions sets credentials when 'credentials' is not empty", function (assert) { assert.expect(1); - let credentials = 'include'; + const credentials = 'include'; const postData = { url: 'https://emberjs.com', method: 'POST', diff --git a/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js b/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js index 20c474009dd..1eb201150f8 100644 --- a/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js +++ b/tests/main/tests/unit/adapters/rest-adapter/group-records-for-find-many-test.js @@ -37,17 +37,17 @@ module( ids: options.data.ids, }); - let queryString = options.data.ids + const queryString = options.data.ids .map((i) => { return 'ids%5B%5D=' + i; }) .join('&'); - let fullUrl = url + '?' + queryString; + const fullUrl = url + '?' + queryString; maxLength = this.maxURLLength; lengths.push(fullUrl.length); - let testRecords = options.data.ids.map((id) => ({ id })); + const testRecords = options.data.ids.map((id) => ({ id })); return Promise.resolve({ testRecords: testRecords }); } } @@ -60,7 +60,7 @@ module( }); test('groupRecordsForFindMany - findMany', async function (assert) { - let wait = []; + const wait = []; for (let i = 1; i <= 1024; i++) { wait.push(store.findRecord('test-record', String(i))); } @@ -73,7 +73,7 @@ module( }); test('groupRecordsForFindMany works for encodeURIComponent-ified ids', async function (assert) { - let wait = []; + const wait = []; wait.push(store.findRecord('test-record', 'my-id:1')); wait.push(store.findRecord('test-record', 'my-id:2')); @@ -88,10 +88,10 @@ module( test('_stripIDFromURL works with id being encoded - #4190', function (assert) { store._fetchManager = new FetchManager(store); - let record = store.createRecord('test-record', { id: 'id:123' }); - let adapter = store.adapterFor('test-record'); - let snapshot = store._fetchManager.createSnapshot(recordIdentifierFor(record)); - let strippedUrl = adapter._stripIDFromURL(store, snapshot); + const record = store.createRecord('test-record', { id: 'id:123' }); + const adapter = store.adapterFor('test-record'); + const snapshot = store._fetchManager.createSnapshot(recordIdentifierFor(record)); + const strippedUrl = adapter._stripIDFromURL(store, snapshot); assert.strictEqual(strippedUrl, '/testRecords/'); }); diff --git a/tests/main/tests/unit/custom-class-support/custom-class-model-test.ts b/tests/main/tests/unit/custom-class-support/custom-class-model-test.ts index d618217bd3a..ef2e8fd5dcd 100644 --- a/tests/main/tests/unit/custom-class-support/custom-class-model-test.ts +++ b/tests/main/tests/unit/custom-class-support/custom-class-model-test.ts @@ -1,4 +1,3 @@ -import type { RecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import { module, test } from 'qunit'; import Store from 'ember-data/store'; @@ -7,9 +6,9 @@ import { setupTest } from 'ember-qunit'; import JSONAPIAdapter from '@ember-data/adapter/json-api'; import type { Snapshot } from '@ember-data/legacy-compat/-private'; import JSONAPISerializer from '@ember-data/serializer/json-api'; -import { Cache } from '@ember-data/store/-types/q/cache'; -import type { SchemaService } from '@ember-data/store/-types/q/schema-service'; -import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; +import type { Cache } from '@ember-data/store/-types/q/cache'; +import type { FieldSchema, SchemaService } from '@ember-data/store/-types/q/schema-service'; +import type { RecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; module('unit/model - Custom Class Model', function (hooks: NestedHooks) { @@ -26,7 +25,7 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { class TestSchema { attributesDefinitionFor(identifier: { type: T }): AttributesSchema { - let schema: AttributesSchema = {}; + const schema: AttributesSchema = {}; schema.name = { kind: 'attribute', options: {}, @@ -94,7 +93,6 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { ); owner.register('serializer:application', JSONAPISerializer); // @ts-expect-error missing type - // eslint-disable-next-line @typescript-eslint/no-unsafe-call owner.unregister('service:store'); }); @@ -150,7 +148,7 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { } this.owner.register('service:store', CreationStore); const store = this.owner.lookup('service:store') as Store; - let person = store.createRecord('person', { name: 'chris', otherProp: 'unk' }) as Record; + const person = store.createRecord('person', { name: 'chris', otherProp: 'unk' }) as Record; assert.strictEqual(returnValue, person, 'createRecord returns the instantiated record'); assert.deepEqual(returnValue, person, 'record instantiating does not modify the returned value'); }); @@ -240,7 +238,7 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { } this.owner.register('service:store', CustomStore); const store = this.owner.lookup('service:store') as Store; - class TestSchema { + class TestSchema2 { attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema { assert.step('Schema:attributesDefinitionFor'); if (typeof identifier === 'string') { @@ -325,10 +323,10 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { } } - let schema: SchemaService = new TestSchema(); + const schema: SchemaService = new TestSchema2(); store.registerSchemaDefinitionService(schema); assert.verifySteps([]); - let person = store.createRecord('person', { name: 'chris' }) as Person; + const person = store.createRecord('person', { name: 'chris' }) as Person; assert.verifySteps([ 'Schema:relationshipsDefinitionFor', 'Schema:fields', @@ -357,8 +355,8 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { ); this.owner.register('service:store', CustomStore); const store = this.owner.lookup('service:store') as Store; - let person = store.createRecord('person', { name: 'chris' }); - let promisePerson = await store.saveRecord(person); + const person = store.createRecord('person', { name: 'chris' }); + const promisePerson = await store.saveRecord(person); assert.strictEqual(person, promisePerson, 'save promise resolves with the same record'); }); @@ -393,7 +391,7 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { this.owner.register('service:store', CreationStore); const store = this.owner.lookup('service:store') as unknown as Store; const rd: Cache = store.cache; - let person = store.push({ data: { type: 'person', id: '1', attributes: { name: 'chris' } } }); + const person = store.push({ data: { type: 'person', id: '1', attributes: { name: 'chris' } } }); store.deleteRecord(person); assert.true(rd.isDeleted(ident!), 'record has been marked as deleted'); await store.saveRecord(person); @@ -423,9 +421,9 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { } this.owner.register('service:store', CustomStore); const store = this.owner.lookup('service:store') as Store; - class TestSchema { + class TestSchema2 { attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema { - let modelName = (identifier as RecordIdentifier).type || identifier; + const modelName = (identifier as RecordIdentifier).type || identifier; if (modelName === 'person') { return { name: { @@ -475,7 +473,7 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { } relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema { - let modelName = (identifier as RecordIdentifier).type || identifier; + const modelName = (identifier as RecordIdentifier).type || identifier; if (modelName === 'person') { return { house: { @@ -497,9 +495,9 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { return true; } } - const schema = new TestSchema(); + const schema = new TestSchema2(); store.registerSchemaDefinitionService(schema); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '7', @@ -507,7 +505,7 @@ module('unit/model - Custom Class Model', function (hooks: NestedHooks) { relationships: { house: { data: { type: 'house', id: '1' } } }, }, }); - let serialized = store.serializeRecord(person, { includeId: true }); + const serialized = store.serializeRecord(person, { includeId: true }); assert.deepEqual( { data: { diff --git a/tests/main/tests/unit/many-array-test.js b/tests/main/tests/unit/many-array-test.js index 6edd7dbcb2a..2dc76d2e83c 100644 --- a/tests/main/tests/unit/many-array-test.js +++ b/tests/main/tests/unit/many-array-test.js @@ -62,7 +62,7 @@ module('unit/many_array - ManyArray', function (hooks) { ], }); - let post = store.peekRecord('post', 3); + const post = store.peekRecord('post', 3); await post.tags.save().then(() => { assert.ok(true, 'manyArray.save() promise resolved'); diff --git a/tests/main/tests/unit/model-test.js b/tests/main/tests/unit/model-test.js index 788cc6de947..0d5db5636de 100644 --- a/tests/main/tests/unit/model-test.js +++ b/tests/main/tests/unit/model-test.js @@ -18,7 +18,7 @@ module('unit/model - Model', function (hooks) { let store, adapter; hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; class Person extends Model { @attr('string') @@ -45,7 +45,7 @@ module('unit/model - Model', function (hooks) { module('currentState', function () { test('supports pushedData in root.deleted.uncommitted', async function (assert) { - let record = store.push({ + const record = store.push({ data: { type: 'person', id: '1', @@ -73,7 +73,7 @@ module('unit/model - Model', function (hooks) { return Promise.resolve({ data: null }); }; - let record = store.push({ + const record = store.push({ data: { type: 'person', id: '1', @@ -118,7 +118,7 @@ module('unit/model - Model', function (hooks) { return Promise.resolve({ data: null }); }; - let record = store.push({ + const record = store.push({ data: { type: 'person', id: '1', @@ -157,7 +157,7 @@ module('unit/model - Model', function (hooks) { }); test('currentState is accessible when the record is created', async function (assert) { - let record = store.push({ + const record = store.push({ data: { type: 'person', id: '1', @@ -181,13 +181,13 @@ module('unit/model - Model', function (hooks) { }, }); - let record = await store.findRecord('person', '1'); + const record = await store.findRecord('person', '1'); assert.strictEqual(get(record, 'id'), '1', 'reports id as id by default'); }); test("a record's id is included in its toString representation", async function (assert) { - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -208,7 +208,7 @@ module('unit/model - Model', function (hooks) { this.owner.register('model:test-model', TestModel); assert.expectAssertion(() => { - let ModelClass = store.modelFor('test-model'); + const ModelClass = store.modelFor('test-model'); get(ModelClass, 'attributes'); }, /You may not set `id` as an attribute on your model/); @@ -236,7 +236,7 @@ module('unit/model - Model', function (hooks) { // such as `watch` which is particularly problematic assert.expect(1); - let hasWatchMethod = Object.prototype.watch; + const hasWatchMethod = Object.prototype.watch; try { if (!hasWatchMethod) { Object.prototype.watch = function () {}; @@ -249,7 +249,7 @@ module('unit/model - Model', function (hooks) { }, }); - let record = await store.findRecord('person', 'watch'); + const record = await store.findRecord('person', 'watch'); assert.strictEqual(get(record, 'id'), 'watch', 'record is successfully created and could be found by its id'); } finally { @@ -293,17 +293,17 @@ module('unit/model - Model', function (hooks) { }); test('setting the id during createRecord should correctly update the id', async function (assert) { - let person = store.createRecord('person', { id: 'john' }); + const person = store.createRecord('person', { id: 'john' }); assert.strictEqual(person.id, 'john', 'new id should be correctly set.'); - let record = store.peekRecord('person', 'john'); + const record = store.peekRecord('person', 'john'); assert.strictEqual(person, record, 'The cache has an entry for john'); }); test('setting the id after createRecord should correctly update the id', async function (assert) { - let person = store.createRecord('person'); + const person = store.createRecord('person'); assert.strictEqual(person.id, null, 'initial created model id should be null'); @@ -311,13 +311,13 @@ module('unit/model - Model', function (hooks) { assert.strictEqual(person.id, 'john', 'new id should be correctly set.'); - let record = store.peekRecord('person', 'john'); + const record = store.peekRecord('person', 'john'); assert.strictEqual(person, record, 'The cache has an entry for john'); }); testInDebug('mutating the id after createRecord but before save works', async function (assert) { - let person = store.createRecord('person', { id: 'chris' }); + const person = store.createRecord('person', { id: 'chris' }); assert.strictEqual(person.id, 'chris', 'initial created model id should be null'); @@ -328,8 +328,8 @@ module('unit/model - Model', function (hooks) { assert.ok(true, 'we did throw'); } - let chris = store.peekRecord('person', 'chris'); - let john = store.peekRecord('person', 'john'); + const chris = store.peekRecord('person', 'chris'); + const john = store.peekRecord('person', 'john'); assert.ok(chris === person, 'The cache still has an entry for chris'); assert.ok(john === null, 'The cache has no entry for john'); @@ -344,7 +344,7 @@ module('unit/model - Model', function (hooks) { }); this.owner.register('model:odd-person', OddPerson); - let person = store.createRecord('odd-person'); + const person = store.createRecord('odd-person'); let oddId = person.idComputed; assert.strictEqual(oddId, null, 'initial computed get is null'); @@ -373,7 +373,7 @@ module('unit/model - Model', function (hooks) { // we peek it instead of getting the return of push to make sure // we can locate it in the identity map - let record = store.peekRecord('person', 0); + const record = store.peekRecord('person', 0); assert.strictEqual(record.name, 'Tom Dale', 'found record with id 0'); }); @@ -392,8 +392,8 @@ module('unit/model - Model', function (hooks) { this.owner.register('model:native-tag', NativeTag); this.owner.register('model:legacy-tag', LegacyTag); - let nativeTag = store.createRecord('native-tag', { name: 'test native' }); - let legacyTag = store.createRecord('legacy-tag', { name: 'test legacy' }); + const nativeTag = store.createRecord('native-tag', { name: 'test native' }); + const legacyTag = store.createRecord('legacy-tag', { name: 'test legacy' }); assert.strictEqual(get(nativeTag, 'name'), 'test native', 'the value is persisted'); assert.strictEqual(get(legacyTag, 'name'), 'test legacy', 'the value is persisted'); @@ -411,8 +411,8 @@ module('unit/model - Model', function (hooks) { this.owner.register('model:native-tag', NativeTag); this.owner.register('model:legacy-tag', LegacyTag); - let nativeTag = store.createRecord('native-tag'); - let legacyTag = store.createRecord('legacy-tag'); + const nativeTag = store.createRecord('native-tag'); + const legacyTag = store.createRecord('legacy-tag'); assert.strictEqual(get(nativeTag, 'name'), 'unknown native tag', 'the default value is found'); assert.strictEqual(get(legacyTag, 'name'), 'unknown legacy tag', 'the default value is found'); @@ -429,7 +429,7 @@ module('unit/model - Model', function (hooks) { } this.owner.register('model:tag', Tag); - let tag = store.createRecord('tag'); + const tag = store.createRecord('tag'); assert.strictEqual(get(tag, 'createdAt'), 'le default value', 'the defaultValue function is evaluated'); }); @@ -447,7 +447,7 @@ module('unit/model - Model', function (hooks) { } this.owner.register('model:tag', Tag); - let tag = store.createRecord('tag'); + const tag = store.createRecord('tag'); get(tag, 'createdAt'); }); @@ -459,7 +459,7 @@ module('unit/model - Model', function (hooks) { } this.owner.register('model:tag', Tag); - let tag = store.createRecord('tag'); + const tag = store.createRecord('tag'); assert.expectAssertion(() => { get(tag, 'tagInfo'); @@ -470,7 +470,7 @@ module('unit/model - Model', function (hooks) { module('Attribute Transforms', function () { function converts(testName, type, provided, expected, options = {}) { test(testName, async function (assert) { - let { owner } = this; + const { owner } = this; class TestModel extends Model { @attr(type, options) name; @@ -481,7 +481,7 @@ module('unit/model - Model', function (hooks) { store.push(store.normalize('model', { id: '1', name: provided })); store.push(store.normalize('model', { id: '2' })); - let record = store.peekRecord('model', 1); + const record = store.peekRecord('model', 1); assert.deepEqual(get(record, 'name'), expected, type + ' coerces ' + provided + ' to ' + expected); }); @@ -489,7 +489,7 @@ module('unit/model - Model', function (hooks) { function convertsFromServer(testName, type, provided, expected) { test(testName, async function (assert) { - let { owner } = this; + const { owner } = this; class TestModel extends Model { @attr(type) name; @@ -498,7 +498,7 @@ module('unit/model - Model', function (hooks) { owner.register('model:model', TestModel); owner.register('serializer:model', JSONSerializer); - let record = store.push( + const record = store.push( store.normalize('model', { id: '1', name: provided, @@ -511,7 +511,7 @@ module('unit/model - Model', function (hooks) { function convertsWhenSet(testName, type, provided, expected) { test(testName, async function (assert) { - let { owner } = this; + const { owner } = this; class TestModel extends Model { @attr(type) name; @@ -520,7 +520,7 @@ module('unit/model - Model', function (hooks) { owner.register('model:model', TestModel); owner.register('serializer:model', JSONSerializer); - let record = store.push({ + const record = store.push({ data: { type: 'model', id: '2', @@ -568,8 +568,8 @@ module('unit/model - Model', function (hooks) { converts('null-to-null', 'date', null, null); converts('undefined-to-undefined', 'date', undefined, undefined); - let dateString = '2011-12-31T00:08:16.000Z'; - let date = new Date(dateString); + const dateString = '2011-12-31T00:08:16.000Z'; + const date = new Date(dateString); convertsFromServer('string-to-Date', 'date', dateString, date); convertsWhenSet('Date-to-string', 'date', date, dateString); @@ -578,7 +578,7 @@ module('unit/model - Model', function (hooks) { module('Reserved Props', function () { testInDebug(`don't allow setting of readOnly state props`, async function (assert) { - let record = store.createRecord('person'); + const record = store.createRecord('person'); if (navigator.userAgent.includes('Firefox/')) { assert.expectAssertion(() => { @@ -602,7 +602,7 @@ module('unit/model - Model', function (hooks) { }; function testReservedProperty(prop) { - let testName = `A subclass of Model cannot use the reserved property '${prop}'`; + const testName = `A subclass of Model cannot use the reserved property '${prop}'`; testInDebug(testName, async function (assert) { const NativePost = PROP_MAP[prop]; @@ -676,14 +676,14 @@ module('unit/model - Model', function (hooks) { }, }); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); assert.strictEqual(get(person, 'currentState.stateName'), 'root.loaded.saved', 'model is in loaded state'); assert.true(get(person, 'isLoaded'), 'model is loaded'); }); test('Pushing a record into the store should transition new records to the loaded state', async function (assert) { - let person = store.createRecord('person', { id: '1', name: 'TomHuda' }); + const person = store.createRecord('person', { id: '1', name: 'TomHuda' }); assert.true(person.isNew, 'createRecord should put records into the new state'); @@ -753,7 +753,7 @@ module('unit/model - Model', function (hooks) { test('a Model can update its attributes', async function (assert) { assert.expect(1); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '2', @@ -775,7 +775,7 @@ module('unit/model - Model', function (hooks) { this.owner.register('model:tag', Tag); - let tag = store.createRecord('tag'); + const tag = store.createRecord('tag'); assert.strictEqual(get(tag, 'name'), 'unknown', 'the default value is found'); set(tag, 'name', null); @@ -805,7 +805,7 @@ module('unit/model - Model', function (hooks) { this.owner.register('model:native-tag', NativeTag); this.owner.register('model:legacy-tag', LegacyTag); - let legacyTag = store.createRecord('legacy-tag', { name: 'old' }); + const legacyTag = store.createRecord('legacy-tag', { name: 'old' }); assert.strictEqual(get(legacyTag, 'name'), 'old', 'precond - name is correct'); set(legacyTag, 'name', 'edited'); @@ -814,7 +814,7 @@ module('unit/model - Model', function (hooks) { set(legacyTag, 'title', 'new'); assert.strictEqual(get(legacyTag, 'name'), 'new', 'setUnknownProperty was triggered'); - let nativeTag = store.createRecord('native-tag', { name: 'old' }); + const nativeTag = store.createRecord('native-tag', { name: 'old' }); assert.strictEqual(get(nativeTag, 'name'), 'old', 'precond - name is correct'); set(nativeTag, 'name', 'edited'); @@ -847,7 +847,7 @@ module('unit/model - Model', function (hooks) { }); test('setting a property back to its original value cleans the mutated state', async function (assert) { - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -874,7 +874,7 @@ module('unit/model - Model', function (hooks) { module('Mutation', function () { test('can have properties and non-specified properties set on it', async function (assert) { - let record = store.createRecord('person', { isDrugAddict: false, notAnAttr: 'my value' }); + const record = store.createRecord('person', { isDrugAddict: false, notAnAttr: 'my value' }); set(record, 'name', 'bar'); set(record, 'anotherNotAnAttr', 'my other value'); @@ -896,7 +896,7 @@ module('unit/model - Model', function (hooks) { }, }); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); assert.false(person.hasDirtyAttributes, 'precond - person record should not be dirty'); @@ -918,7 +918,7 @@ module('unit/model - Model', function (hooks) { }, }); - let person = await store.findRecord('person', '1'); + const person = await store.findRecord('person', '1'); assert.false(person.hasDirtyAttributes, 'precond - person record should not be dirty'); @@ -946,10 +946,10 @@ module('unit/model - Model', function (hooks) { }, }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); person.set('name', 'Thomas'); - let saving = person.save(); + const saving = person.save(); assert.strictEqual(person.name, 'Thomas'); @@ -976,7 +976,7 @@ module('unit/model - Model', function (hooks) { }, }); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); assert.false(person.hasDirtyAttributes, 'precond - person record should not be dirty'); person.set('isDrugAddict', false); @@ -1013,7 +1013,7 @@ module('unit/model - Model', function (hooks) { }, }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); assert.false(person.hasDirtyAttributes, 'precond - person record should not be dirty'); person.set('name', 'Wolf'); @@ -1061,7 +1061,7 @@ module('unit/model - Model', function (hooks) { }, }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); assert.false(person.hasDirtyAttributes, 'precond - person record should not be dirty'); person.set('name', 'Wolf'); @@ -1093,8 +1093,8 @@ module('unit/model - Model', function (hooks) { } this.owner.register('model:post', Post); - let dateString = 'Sat, 31 Dec 2011 00:08:16 GMT'; - let date = new Date(dateString); + const dateString = 'Sat, 31 Dec 2011 00:08:16 GMT'; + const date = new Date(dateString); store.push({ data: { @@ -1103,7 +1103,7 @@ module('unit/model - Model', function (hooks) { }, }); - let record = await store.findRecord('post', '1'); + const record = await store.findRecord('post', '1'); record.set('updatedAt', date); @@ -1127,7 +1127,7 @@ module('unit/model - Model', function (hooks) { this.owner.register('model:mascot', Mascot); - let mascot = store.push({ + const mascot = store.push({ data: { type: 'mascot', id: '1', @@ -1144,7 +1144,7 @@ module('unit/model - Model', function (hooks) { mascot.set('likes', 'Ember.js'); // changed value mascot.set('isMascot', true); // same value - let changedAttributes = mascot.changedAttributes(); + const changedAttributes = mascot.changedAttributes(); assert.deepEqual(changedAttributes.name, [undefined, 'Tomster']); assert.deepEqual(changedAttributes.likes, ['JavaScript', 'Ember.js']); @@ -1179,9 +1179,7 @@ module('unit/model - Model', function (hooks) { return Promise.resolve({ data: { id: '1', type: 'mascot' } }); }; - let cat; - - cat = store.createRecord('mascot'); + const cat = store.createRecord('mascot'); cat.setProperties({ name: 'Argon', likes: 'Cheese', @@ -1192,6 +1190,7 @@ module('unit/model - Model', function (hooks) { test('changedAttributes() works while the record is being updated', async function (assert) { assert.expect(1); + // eslint-disable-next-line prefer-const let cat; class Mascot extends Model { @@ -1274,6 +1273,7 @@ module('unit/model - Model', function (hooks) { test('@attr decorator works without parens', async function (assert) { assert.expect(1); + // eslint-disable-next-line prefer-const let cat; class Mascot extends Model { @@ -1309,7 +1309,7 @@ module('unit/model - Model', function (hooks) { module('Misc', function () { testInDebug('Calling record.attr() asserts', async function (assert) { - let person = store.createRecord('person', { id: '1', name: 'TomHuda' }); + const person = store.createRecord('person', { id: '1', name: 'TomHuda' }); assert.expectAssertion(() => { person.attr(); diff --git a/tests/main/tests/unit/model/attr-test.js b/tests/main/tests/unit/model/attr-test.js index 428f6b5be49..893379aafee 100644 --- a/tests/main/tests/unit/model/attr-test.js +++ b/tests/main/tests/unit/model/attr-test.js @@ -24,14 +24,14 @@ module('unit/model/attr | attr syntax', function (hooks) { owner.register('model:user', User); - let UserModel = store.modelFor('user'); - let attrs = UserModel.attributes; + const UserModel = store.modelFor('user'); + const attrs = UserModel.attributes; assert.true(attrs.has('name'), 'We have the attr: name'); assert.true(attrs.has('nameWithTransform'), 'We have the attr: nameWithTransform'); assert.true(attrs.has('nameWithOptions'), 'We have the attr: nameWithOptions'); assert.true(attrs.has('nameWithTransformAndOptions'), 'We have the attr: nameWithTransformAndOptions'); - let userRecord = store.push({ + const userRecord = store.push({ data: { type: 'user', id: '1', @@ -64,14 +64,14 @@ module('unit/model/attr | attr syntax', function (hooks) { owner.register('model:user', User); - let UserModel = store.modelFor('user'); - let attrs = UserModel.attributes; + const UserModel = store.modelFor('user'); + const attrs = UserModel.attributes; assert.true(attrs.has('name'), 'We have the attr: name'); assert.true(attrs.has('nameWithTransform'), 'We have the attr: nameWithTransform'); assert.true(attrs.has('nameWithOptions'), 'We have the attr: nameWithOptions'); assert.true(attrs.has('nameWithTransformAndOptions'), 'We have the attr: nameWithTransformAndOptions'); - let userRecord = store.push({ + const userRecord = store.push({ data: { type: 'user', id: '1', @@ -105,14 +105,14 @@ module('unit/model/attr | attr syntax', function (hooks) { owner.register('model:user', User); - let UserModel = store.modelFor('user'); - let attrs = UserModel.attributes; + const UserModel = store.modelFor('user'); + const attrs = UserModel.attributes; assert.false(attrs.has('name'), 'We have the attr: name'); assert.false(attrs.has('nameWithTransform'), 'We have the attr: nameWithTransform'); assert.false(attrs.has('nameWithOptions'), 'We have the attr: nameWithOptions'); assert.false(attrs.has('nameWithTransformAndOptions'), 'We have the attr: nameWithTransformAndOptions'); - let userRecord = store.push({ + const userRecord = store.push({ data: { type: 'user', id: '1', @@ -142,11 +142,11 @@ module('unit/model/attr | attr syntax', function (hooks) { owner.register('model:user', User); - let UserModel = store.modelFor('user'); - let attrs = UserModel.attributes; + const UserModel = store.modelFor('user'); + const attrs = UserModel.attributes; assert.true(attrs.has('name'), 'We have the attr: name'); - let userRecord = store.push({ + const userRecord = store.push({ data: { type: 'user', id: '1', @@ -166,11 +166,11 @@ module('unit/model/attr | attr syntax', function (hooks) { owner.register('model:blog', Blog); - let BlogModel = store.modelFor('blog'); - let attrs = BlogModel.attributes; + const BlogModel = store.modelFor('blog'); + const attrs = BlogModel.attributes; assert.true(attrs.has('content'), 'We have the attr: name'); - let userRecord = store.push({ + const userRecord = store.push({ data: { type: 'blog', id: '1', diff --git a/tests/main/tests/unit/model/init-properties-test.js b/tests/main/tests/unit/model/init-properties-test.js index 1521b698623..433e6aead41 100644 --- a/tests/main/tests/unit/model/init-properties-test.js +++ b/tests/main/tests/unit/model/init-properties-test.js @@ -10,8 +10,6 @@ import Model, { attr, belongsTo, hasMany } from '@ember-data/model'; import JSONAPISerializer from '@ember-data/serializer/json-api'; function setupModels(owner, testState) { - let types; - const Comment = Model.extend({ text: attr(), post: belongsTo('post', { async: false, inverse: 'comments' }), @@ -32,7 +30,7 @@ function setupModels(owner, testState) { }, }); - types = { + const types = { Author, Comment, Post, @@ -45,8 +43,8 @@ function setupModels(owner, testState) { owner.register('adapter:application', JSONAPIAdapter.extend()); owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = owner.lookup('service:store'); + const adapter = store.adapterFor('application'); return { adapter, store }; } @@ -56,8 +54,6 @@ module('unit/model - init properties', function (hooks) { test('createRecord(properties) makes properties available during record init', function (assert) { assert.expect(4); - let comment; - let author; function testState(types, record) { assert.strictEqual(get(record, 'title'), 'My Post', 'Attrs are available as expected'); @@ -66,9 +62,9 @@ module('unit/model - init properties', function (hooks) { assert.ok(record.comments.at(0) instanceof types.Comment, 'hasMany relationships are available as expected'); } - let { store } = setupModels(this.owner, testState); + const { store } = setupModels(this.owner, testState); - comment = store.push({ + const comment = store.push({ data: { type: 'comment', id: '1', @@ -77,7 +73,7 @@ module('unit/model - init properties', function (hooks) { }, }, }); - author = store.push({ + const author = store.push({ data: { type: 'author', id: '1', @@ -104,7 +100,7 @@ module('unit/model - init properties', function (hooks) { assert.ok(record.comments.at(0) instanceof types.Comment, 'hasMany relationships are available as expected'); } - let { store } = setupModels(this.owner, testState); + const { store } = setupModels(this.owner, testState); store.push({ data: { @@ -152,7 +148,7 @@ module('unit/model - init properties', function (hooks) { assert.ok(record.comments.at(0) instanceof types.Comment, 'hasMany relationships are available as expected'); } - let { adapter, store } = setupModels(this.owner, testState); + const { adapter, store } = setupModels(this.owner, testState); adapter.findRecord = () => { return Promise.resolve({ @@ -202,7 +198,7 @@ module('unit/model - init properties', function (hooks) { assert.ok(record.comments.at(0) instanceof types.Comment, 'hasMany relationships are available as expected'); } - let { adapter, store } = setupModels(this.owner, testState); + const { adapter, store } = setupModels(this.owner, testState); adapter.queryRecord = () => { return Promise.resolve({ @@ -243,7 +239,7 @@ module('unit/model - init properties', function (hooks) { await store.queryRecord('post', { id: '1' }); }); - test('Model class does not get properties passed to setUknownProperty accidentally', function (assert) { + test('Model class does not get properties passed to setUnknownProperty accidentally', function (assert) { assert.expect(2); // If we end up passing additional properties to init in modelClasses, we will need to come up with a strategy for // how to get setUnknownProperty to continue working @@ -251,8 +247,8 @@ module('unit/model - init properties', function (hooks) { const Post = Model.extend({ title: attr(), setUnknownProperty: function (key, value) { - assert.strictEqual(key, 'randomProp', 'Passed the correct key to setUknownProperty'); - assert.strictEqual(value, 'An unknown prop', 'Passed the correct value to setUknownProperty'); + assert.strictEqual(key, 'randomProp', 'Passed the correct key to setUnknownProperty'); + assert.strictEqual(value, 'An unknown prop', 'Passed the correct value to setUnknownProperty'); }, }); @@ -260,7 +256,7 @@ module('unit/model - init properties', function (hooks) { this.owner.register('adapter:application', JSONAPIAdapter.extend()); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.createRecord('post', { title: 'My Post', diff --git a/tests/main/tests/unit/model/merge-test.js b/tests/main/tests/unit/model/merge-test.js index a78bffc9337..3c1ba15e70e 100644 --- a/tests/main/tests/unit/model/merge-test.js +++ b/tests/main/tests/unit/model/merge-test.js @@ -33,8 +33,8 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person = this.store.createRecord('person', { name: 'Tom Dale' }); - let save = person.save(); + const person = this.store.createRecord('person', { name: 'Tom Dale' }); + const save = person.save(); assert.strictEqual(person.name, 'Tom Dale'); @@ -59,7 +59,7 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person = this.store.push({ + const person = this.store.push({ data: { type: 'person', id: '1', @@ -70,7 +70,7 @@ module('unit/model/merge - Merging', function (hooks) { }); person.set('name', 'Thomas Dale'); - let promise = person.save(); + const promise = person.save(); assert.strictEqual(person.name, 'Thomas Dale'); @@ -106,7 +106,7 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person = this.store.push({ + const person = this.store.push({ data: { type: 'person', id: '1', @@ -145,9 +145,7 @@ module('unit/model/merge - Merging', function (hooks) { }); test('When a record is dirty, pushes are overridden by local changes', function (assert) { - let person; - - person = this.store.push({ + const person = this.store.push({ data: { type: 'person', id: '1', @@ -188,7 +186,7 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person = this.store.push({ + const person = this.store.push({ data: { type: 'person', id: '1', @@ -240,7 +238,7 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person = this.store.push({ + const person = this.store.push({ data: { type: 'person', id: '1', @@ -267,7 +265,7 @@ module('unit/model/merge - Merging', function (hooks) { this.owner.register('adapter:application', ApplicationAdapter); - let person = this.store.push({ + const person = this.store.push({ data: { type: 'person', id: '1', diff --git a/tests/main/tests/unit/model/relationships-test.js b/tests/main/tests/unit/model/relationships-test.js index 817e32be255..988d410df99 100644 --- a/tests/main/tests/unit/model/relationships-test.js +++ b/tests/main/tests/unit/model/relationships-test.js @@ -27,7 +27,7 @@ module('[@ember-data/model] unit - relationships', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:occupation', Occupation); owner.register('model:person', Person); @@ -38,11 +38,11 @@ module('[@ember-data/model] unit - relationships', function (hooks) { }); test('exposes a hash of the relationships on a model', function (assert) { - let Person = store.modelFor('person'); + const Person = store.modelFor('person'); - let relationships = get(Person, 'relationships'); + const relationships = get(Person, 'relationships'); function extractDetails(key) { - let descs = relationships.get(key); + const descs = relationships.get(key); return descs.map((desc) => { return { @@ -80,7 +80,7 @@ module('[@ember-data/model] unit - relationships', function (hooks) { }); test('eachRelatedType() iterates over relations without duplication', function (assert) { - let relations = []; + const relations = []; Person.eachRelatedType((modelName) => relations.push(modelName)); @@ -88,7 +88,7 @@ module('[@ember-data/model] unit - relationships', function (hooks) { }); test('normalizing belongsTo relationship names', function (assert) { - let User = store.modelFor('user'); + const User = store.modelFor('user'); const relationships = get(User, 'relationships'); @@ -100,8 +100,7 @@ module('[@ember-data/model] unit - relationships', function (hooks) { }); test('normalizing hasMany relationship names', function (assert) { - let store; - let { owner } = this; + const { owner } = this; class StreamItem extends Model { @belongsTo('user', { async: true, inverse: 'streamItems' }) user; @@ -115,9 +114,9 @@ module('[@ember-data/model] unit - relationships', function (hooks) { owner.register('model:stream-item', StreamItem); owner.register('model:user', User); - store = owner.lookup('service:store'); + const store = owner.lookup('service:store'); - let user = store.modelFor('user'); + const user = store.modelFor('user'); const relationships = get(user, 'relationships'); diff --git a/tests/main/tests/unit/model/relationships/belongs-to-test.js b/tests/main/tests/unit/model/relationships/belongs-to-test.js index 278844f61e9..d10e8fb30fa 100644 --- a/tests/main/tests/unit/model/relationships/belongs-to-test.js +++ b/tests/main/tests/unit/model/relationships/belongs-to-test.js @@ -34,8 +34,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -108,8 +108,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -140,9 +140,9 @@ module('unit/model/relationships - belongsTo', function (hooks) { ], }); - let person = store.peekRecord('person', '2'); + const person = store.peekRecord('person', '2'); - let tagDidChange = () => assert.ok(false, 'observer is not called'); + const tagDidChange = () => assert.ok(false, 'observer is not called'); person.addObserver('tag', tagDidChange); @@ -167,8 +167,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { if (type === Person) { @@ -217,8 +217,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.coalesceFindRequests = false; @@ -277,8 +277,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { } }; - let persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; - let [tag1, tag2] = await Promise.all(persons.map((person) => person.tag)); + const persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; + const [tag1, tag2] = await Promise.all(persons.map((person) => person.tag)); assert.strictEqual(get(tag1, 'name'), 'friendly', 'Tom Dale is now friendly'); assert.true(get(tag1, 'isLoaded'), "Tom Dale's tag is now loaded"); @@ -302,8 +302,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.coalesceFindRequests = true; @@ -360,8 +360,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { throw new Error('findRecord should not be called'); }; - let persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; - let [tag1, tag2] = await Promise.all(persons.map((person) => person.tag)); + const persons = [store.peekRecord('person', '1'), store.peekRecord('person', '2')]; + const [tag1, tag2] = await Promise.all(persons.map((person) => person.tag)); assert.strictEqual(get(tag1, 'name'), 'friendly', 'Tom Dale is now friendly'); assert.true(get(tag1, 'isLoaded'), "Tom Dale's tag is now loaded"); @@ -385,7 +385,7 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -411,7 +411,7 @@ module('unit/model/relationships - belongsTo', function (hooks) { ], }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); assert.strictEqual(get(person, 'name'), 'Tom Dale', 'The person is now populated'); const tag = await person.tag; assert.strictEqual(get(tag, 'name'), 'friendly', 'Tom Dale is now friendly'); @@ -501,8 +501,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -524,8 +524,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:occupation', Occupation); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -591,8 +591,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:occupation', Occupation); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { assert.strictEqual(snapshot.belongsTo('person').id, '1'); @@ -633,8 +633,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -703,8 +703,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:hobby', Hobby); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -759,8 +759,8 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:hobby', Hobby); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -816,10 +816,10 @@ module('unit/model/relationships - belongsTo', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const theTag = store.push({ data: { type: 'tag', id: '1', attributes: { name: 'Amber' } } }); - let person = store.createRecord('person', { tag: theTag }); + const person = store.createRecord('person', { tag: theTag }); const personTag = person.tag; assert.ok(personTag.then, 'tag should be an async relationship'); const tag = await personTag; diff --git a/tests/main/tests/unit/model/relationships/has-many-test.js b/tests/main/tests/unit/model/relationships/has-many-test.js index 0ebc2f0578b..42eb0600340 100644 --- a/tests/main/tests/unit/model/relationships/has-many-test.js +++ b/tests/main/tests/unit/model/relationships/has-many-test.js @@ -184,8 +184,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:pet', Pet); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { if (type === Tag && id === '12') { @@ -264,7 +264,7 @@ module('unit/model/relationships - hasMany', function (hooks) { assert.strictEqual(person.name, 'Tom Dale', 'precond - retrieves person record from store'); - let tags = person.tags; + const tags = person.tags; assert.strictEqual(tags.length, 1, 'the list of tags should have the correct length'); assert.strictEqual(tags.at(0).name, 'friendly', 'the first tag should be a Tag'); @@ -329,7 +329,7 @@ module('unit/model/relationships - hasMany', function (hooks) { assert.strictEqual(cyvid.name, 'Cyvid Hamluck', 'precond - retrieves person record from store'); - let pets = cyvid.pets; + const pets = cyvid.pets; assert.strictEqual(pets.length, 1, 'the list of pets should have the correct length'); assert.strictEqual(pets.at(0).name, 'fluffy', 'the first pet should be correct'); @@ -373,8 +373,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -407,7 +407,7 @@ module('unit/model/relationships - hasMany', function (hooks) { ], }); - let tag = store.peekRecord('tag', 1); + const tag = store.peekRecord('tag', 1); tag.addObserver('people', () => { assert.ok(false, 'observer is not called'); }); @@ -439,8 +439,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -459,7 +459,7 @@ module('unit/model/relationships - hasMany', function (hooks) { }, }); - let tag = store.peekRecord('tag', 1); + const tag = store.peekRecord('tag', 1); assert.strictEqual(tag.people.length, 0, 'relationship is correct'); }); @@ -480,8 +480,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -539,8 +539,8 @@ module('unit/model/relationships - hasMany', function (hooks) { }, }); - let tag = store.peekRecord('tag', 1); - let person = store.peekRecord('person', 1); + const tag = store.peekRecord('tag', 1); + const person = store.peekRecord('person', 1); assert.strictEqual(person.tag, null, 'relationship is empty'); assert.strictEqual(tag.people.length, 0, 'relationship is correct'); @@ -578,7 +578,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // first we push in data with the relationship store.push({ @@ -622,7 +622,7 @@ module('unit/model/relationships - hasMany', function (hooks) { ], }); - let tag = store.peekRecord('tag', 1); + const tag = store.peekRecord('tag', 1); assert.strictEqual(tag.people.length, 1, 'relationship does not contain duplicates'); } ); @@ -651,7 +651,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); // first we push in data with the relationship store.push({ @@ -747,11 +747,11 @@ module('unit/model/relationships - hasMany', function (hooks) { ], }); - let tag = store.peekRecord('tag', 1); + const tag = store.peekRecord('tag', 1); assert.strictEqual(tag.people.length, 2, 'relationship does contain all data'); - let person1 = store.peekRecord('person', 1); + const person1 = store.peekRecord('person', 1); assert.strictEqual(person1.tags.length, 2, 'relationship does contain all data'); - let person2 = store.peekRecord('person', 2); + const person2 = store.peekRecord('person', 2); assert.strictEqual(person2.tags.length, 2, 'relationship does contain all data'); }); @@ -771,8 +771,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -852,8 +852,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -877,7 +877,7 @@ module('unit/model/relationships - hasMany', function (hooks) { }, }); - let eddy = store.peekRecord('person', 1); + const eddy = store.peekRecord('person', 1); assert.deepEqual( eddy.trueFriends.map((r) => r.name), ['Edward II'], @@ -908,8 +908,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:pet', Pet); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id, snapshot) { if (type === Tag && id === '12') { @@ -1001,7 +1001,7 @@ module('unit/model/relationships - hasMany', function (hooks) { ); const tagsAgain = await wycats.tags; - let newTag = store.createRecord('tag'); + const newTag = store.createRecord('tag'); tagsAgain.push(newTag); await settled(); @@ -1019,7 +1019,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.strictEqual( store.modelFor('person').typeForRelationship('tags', store), @@ -1038,7 +1038,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.strictEqual( store.modelFor('person').typeForRelationship('tags', store), @@ -1057,7 +1057,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.strictEqual( store.modelFor('person').typeForRelationship('tag', store), @@ -1078,7 +1078,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.strictEqual( store.modelFor('person').typeForRelationship('tags', store), @@ -1102,8 +1102,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:tag', Tag); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -1170,8 +1170,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.coalesceFindRequests = true; adapter.findMany = function (store, type, ids, snapshots) { @@ -1233,8 +1233,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -1290,8 +1290,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:pet', Pet); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -1386,8 +1386,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:pet', Pet); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -1466,7 +1466,7 @@ module('unit/model/relationships - hasMany', function (hooks) { }, }); - let hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; + const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; assert.todo.deepEqual( pets.map((p) => p.id), @@ -1499,8 +1499,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:pet', Pet); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -1584,7 +1584,7 @@ module('unit/model/relationships - hasMany', function (hooks) { }, }); - let hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; + const hasManyCanonical = person.hasMany('pets').hasManyRelationship.remoteState; assert.todo.deepEqual( pets.map((p) => p.id), @@ -1615,8 +1615,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:pet', Pet); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -1711,8 +1711,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:dog', Dog); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -1784,8 +1784,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:dog', Dog); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -1857,8 +1857,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:dog', Dog); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -1935,7 +1935,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:car', Car); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -1959,8 +1959,8 @@ module('unit/model/relationships - hasMany', function (hooks) { ], }); - let person = store.peekRecord('person', 1); - let cars = person.cars; + const person = store.peekRecord('person', 1); + const cars = person.cars; assert.strictEqual(cars.length, 2); @@ -2007,8 +2007,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:person', Person); this.owner.register('model:pet', Pet); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = () => { @@ -2120,7 +2120,7 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -2165,8 +2165,8 @@ module('unit/model/relationships - hasMany', function (hooks) { ], }); - let tom = store.peekRecord('person', '1'); - let sylvain = store.peekRecord('person', '2'); + const tom = store.peekRecord('person', '1'); + const sylvain = store.peekRecord('person', '2'); // Test that since sylvain.tags instanceof ManyArray, // adding records on Relationship iterates correctly. tom.tags.length = 0; @@ -2192,8 +2192,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -2222,7 +2222,7 @@ module('unit/model/relationships - hasMany', function (hooks) { ], }); - let tag = person.tags.at(0); + const tag = person.tags.at(0); assert.strictEqual(tag.name, 'Amber', 'precond - relationships work'); @@ -2245,13 +2245,13 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.createRecord('person'); - let tag1 = store.createRecord('tag'); - let tag2 = store.createRecord('tag'); - let tag3 = store.createRecord('tag'); - let tags = person.tags; + const person = store.createRecord('person'); + const tag1 = store.createRecord('tag'); + const tag2 = store.createRecord('tag'); + const tag3 = store.createRecord('tag'); + const tags = person.tags; tags.push(tag1, tag2, tag3); tags.splice(tags.indexOf(tag2), 1); @@ -2284,8 +2284,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let tag = store.createRecord('tag'); + const store = this.owner.lookup('service:store'); + const tag = store.createRecord('tag'); assert.ok(tag.people instanceof PromiseManyArray, 'people should be an async relationship'); }); @@ -2304,15 +2304,15 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let tag = store.createRecord('tag'); - let people = tag.people; - let peopleCached = tag.people; + const store = this.owner.lookup('service:store'); + const tag = store.createRecord('tag'); + const people = tag.people; + const peopleCached = tag.people; assert.strictEqual(people, peopleCached); tag.notifyPropertyChange('people'); - let notifiedPeople = tag.people; + const notifiedPeople = tag.people; assert.strictEqual(people, notifiedPeople); @@ -2333,10 +2333,10 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let tag = store.createRecord('tag'); - let peopleProxy = tag.people; - let people = await peopleProxy; + const store = this.owner.lookup('service:store'); + const tag = store.createRecord('tag'); + const peopleProxy = tag.people; + const people = await peopleProxy; tag.unloadRecord(); assert.true(people.isDestroying, 'people is destroying sync after unloadRecord'); @@ -2425,7 +2425,7 @@ module('unit/model/relationships - hasMany', function (hooks) { }, }); - let post = store.peekRecord('post', '1'); + const post = store.peekRecord('post', '1'); const promise = post.comments; const promise2 = post.comments; @@ -2600,8 +2600,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let tag = store.createRecord('tag'); + const store = this.owner.lookup('service:store'); + const tag = store.createRecord('tag'); tag.hasMany('people').hasManyRelationship; const support = LEGACY_SUPPORT.get(tag); const sync = support._syncArray; @@ -2623,7 +2623,7 @@ module('unit/model/relationships - hasMany', function (hooks) { 'expect people hasMany to not dirty after fetch completes, as we did not hit network' ); - let person = store.createRecord('person'); + const person = store.createRecord('person'); assert.strictEqual(peopleDidChange, 0, 'expect people hasMany to not sync before access'); people = await tag.people; @@ -2651,8 +2651,8 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.findHasMany = function (store, snapshot, url, relationship) { assert.strictEqual(relationship.key, 'tags', 'relationship should be tags'); @@ -2716,9 +2716,9 @@ module('unit/model/relationships - hasMany', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let tag = store.createRecord('tag'); - let person = store.createRecord('person'); + const store = this.owner.lookup('service:store'); + const tag = store.createRecord('tag'); + const person = store.createRecord('person'); assert.expectAssertion(() => { tag.people = person; diff --git a/tests/main/tests/unit/model/relationships/record-array-test.js b/tests/main/tests/unit/model/relationships/record-array-test.js index 8d0aa8ab456..6120d4c7ff4 100644 --- a/tests/main/tests/unit/model/relationships/record-array-test.js +++ b/tests/main/tests/unit/model/relationships/record-array-test.js @@ -25,8 +25,8 @@ module('unit/model/relationships - RecordArray', function (hooks) { this.owner.register('model:tag', Tag); this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -40,7 +40,7 @@ module('unit/model/relationships - RecordArray', function (hooks) { }, }); - let person = await store.findRecord('person', 1); + const person = await store.findRecord('person', 1); person.tags.createRecord({ name: 'cool' }); assert.strictEqual(get(person, 'name'), 'Tom Dale', 'precond - retrieves person record from store'); diff --git a/tests/main/tests/unit/model/rollback-attributes-test.js b/tests/main/tests/unit/model/rollback-attributes-test.js index dd294d80fca..18573be5b24 100644 --- a/tests/main/tests/unit/model/rollback-attributes-test.js +++ b/tests/main/tests/unit/model/rollback-attributes-test.js @@ -28,8 +28,8 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test('changes to attributes can be rolled back', function (assert) { - let store = this.owner.lookup('service:store'); - let person = store.push({ + const store = this.owner.lookup('service:store'); + const person = store.push({ data: { type: 'person', id: '1', @@ -50,8 +50,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test('changes to unassigned attributes can be rolled back', function (assert) { - let store = this.owner.lookup('service:store'); - let person; + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -62,7 +61,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }, }, }); - person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); person.set('firstName', 'Thomas'); assert.strictEqual(person.firstName, 'Thomas'); @@ -78,7 +77,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h const adapter = store.adapterFor('application'); let resolve; - let trap = new Promise((r) => (resolve = r)); + const trap = new Promise((r) => (resolve = r)); adapter.updateRecord = async function (store, type, snapshot) { resolve(); await trap; @@ -121,14 +120,14 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test("a record's changes can be made if it fails to save", async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.updateRecord = function (store, type, snapshot) { return Promise.reject(); }; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -158,15 +157,13 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test(`a deleted record's attributes can be rollbacked if it fails to save, record arrays are updated accordingly`, async function (assert) { - let store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const store = this.owner.lookup('service:store'); + const adapter = store.adapterFor('application'); adapter.deleteRecord = function (store, type, snapshot) { return Promise.reject(); }; - let person, people; - store.push({ data: { type: 'person', @@ -177,8 +174,8 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }, }, }); - person = store.peekRecord('person', 1); - people = store.peekAll('person'); + const person = store.peekRecord('person', 1); + const people = store.peekAll('person'); person.deleteRecord(); @@ -207,8 +204,8 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test(`new record's attributes can be rollbacked`, function (assert) { - let store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { id: '1' }); + const store = this.owner.lookup('service:store'); + const person = store.createRecord('person', { id: '1' }); assert.true(person.isNew, 'must be new'); assert.true(person.hasDirtyAttributes, 'must be dirty'); @@ -221,14 +218,14 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test(`invalid new record's attributes can be rollbacked`, async function (assert) { - let error = new InvalidError([ + const error = new InvalidError([ { detail: 'is invalid', source: { pointer: 'data/attributes/name' }, }, ]); - let adapter = RESTAdapter.extend({ + const adapter = RESTAdapter.extend({ ajax(url, type, hash) { return Promise.reject(error); }, @@ -237,8 +234,8 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h this.owner.register('adapter:application', adapter); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { id: '1' }); + const store = this.owner.lookup('service:store'); + const person = store.createRecord('person', { id: '1' }); assert.true(person.isNew, 'must be new'); assert.true(person.hasDirtyAttributes, 'must be dirty'); @@ -258,9 +255,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test(`invalid record's attributes can be rollbacked after multiple failed calls - #3677`, async function (assert) { - let adapter = RESTAdapter.extend({ + const adapter = RESTAdapter.extend({ ajax(url, type, hash) { - let error = new InvalidError(); + const error = new InvalidError(); return Promise.reject(error); }, }); @@ -268,9 +265,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h this.owner.register('adapter:application', adapter); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -305,9 +302,7 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h }); test(`deleted record's attributes can be rollbacked`, function (assert) { - let store = this.owner.lookup('service:store'); - - let person, people; + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -315,8 +310,8 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h id: '1', }, }); - person = store.peekRecord('person', 1); - people = store.peekAll('person'); + const person = store.peekRecord('person', 1); + const people = store.peekAll('person'); person.deleteRecord(); assert.strictEqual(people.length, 1, 'a deleted record appears in the record array until it is saved'); @@ -455,14 +450,14 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h name: attr(), }); - let error = new InvalidError([ + const error = new InvalidError([ { detail: 'is invalid', source: { pointer: 'data/attributes/name' }, }, ]); - let adapter = RESTAdapter.extend({ + const adapter = RESTAdapter.extend({ ajax(url, type, hash) { return Promise.reject(error); }, @@ -472,8 +467,8 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function (h this.owner.register('adapter:application', adapter); this.owner.register('serializer:application', RESTSerializer.extend()); - let store = this.owner.lookup('service:store'); - let dog = store.push({ + const store = this.owner.lookup('service:store'); + const dog = store.push({ data: { type: 'dog', id: '1', diff --git a/tests/main/tests/unit/promise-proxies-test.js b/tests/main/tests/unit/promise-proxies-test.js index 98c61411b12..5283e7204aa 100644 --- a/tests/main/tests/unit/promise-proxies-test.js +++ b/tests/main/tests/unit/promise-proxies-test.js @@ -13,15 +13,15 @@ module('PromiseManyArray', function () { test('.reload should NOT leak the internal promise, rather return another promiseArray', function (assert) { assert.expect(1); - let content = A(); + const content = A(); content.reload = () => Promise.resolve(content); - let array = PromiseManyArray.create({ + const array = PromiseManyArray.create({ content, }); - let reloaded = array.reload(); + const reloaded = array.reload(); assert.strictEqual(reloaded, array); }); @@ -29,17 +29,16 @@ module('PromiseManyArray', function () { test('.reload should be stable', async function (assert) { assert.expect(19); - let content = A(); - let array; + const content = A(); content.reload = () => { - let p = Promise.resolve(content); + const p = Promise.resolve(content); array._update(p); return p; }; - let promise = Promise.resolve(content); + const promise = Promise.resolve(content); - array = PromiseManyArray.create({ + const array = PromiseManyArray.create({ promise, }); @@ -54,7 +53,7 @@ module('PromiseManyArray', function () { assert.true(array.isSettled, 'should be settled'); assert.true(array.isFulfilled, 'should be fulfilled'); - let reloaded = array.reload(); + const reloaded = array.reload(); assert.false(array.isRejected, 'should NOT be rejected'); assert.true(array.isPending, 'should be pending'); @@ -64,7 +63,7 @@ module('PromiseManyArray', function () { assert.ok(reloaded instanceof PromiseManyArray); assert.strictEqual(reloaded, array); - let value = await reloaded; + const value = await reloaded; assert.false(array.isRejected, 'should NOT be rejected'); assert.false(array.isPending, 'should NOT be pending'); assert.true(array.isSettled, 'should be settled'); @@ -76,11 +75,11 @@ module('PromiseManyArray', function () { test('.set to new promise should be like reload', async function (assert) { assert.expect(18); - let content = A([1, 2, 3]); + const content = A([1, 2, 3]); - let promise = Promise.resolve(content); + const promise = Promise.resolve(content); - let array = PromiseManyArray.create({ + const array = PromiseManyArray.create({ promise, }); @@ -104,7 +103,7 @@ module('PromiseManyArray', function () { assert.ok(array instanceof PromiseManyArray); - let value = await array; + const value = await array; assert.false(array.isRejected, 'should NOT be rejected'); assert.false(array.isPending, 'should NOT be pending'); assert.true(array.isSettled, 'should be settled'); diff --git a/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js b/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js index 1c7d4f08727..00e748de10b 100644 --- a/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js +++ b/tests/main/tests/unit/record-arrays/adapter-populated-record-array-test.js @@ -16,7 +16,7 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR setupTest(hooks); test('default initial state', async function (assert) { - let recordArray = new AdapterPopulatedRecordArray({ + const recordArray = new AdapterPopulatedRecordArray({ type: 'recordType', isLoaded: false, identifiers: [], @@ -32,8 +32,8 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR }); test('custom initial state', async function (assert) { - let store = {}; - let recordArray = new AdapterPopulatedRecordArray({ + const store = {}; + const recordArray = new AdapterPopulatedRecordArray({ type: 'apple', isLoaded: true, identifiers: ['1'], @@ -51,7 +51,7 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR }); testInDebug('mutation throws error', function (assert) { - let recordArray = new AdapterPopulatedRecordArray({ type: 'recordType', identifiers: [] }); + const recordArray = new AdapterPopulatedRecordArray({ type: 'recordType', identifiers: [] }); assert.throws( () => { @@ -64,7 +64,7 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR test('#update uses _update enabling query specific behavior', async function (assert) { let queryCalled = 0; - let deferred = createDeferred(); + const deferred = createDeferred(); const store = { query(modelName, query, options) { @@ -77,7 +77,7 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR }, }; - let recordArray = new AdapterPopulatedRecordArray({ + const recordArray = new AdapterPopulatedRecordArray({ type: 'recordType', store, identifiers: [], @@ -89,7 +89,7 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR assert.strictEqual(queryCalled, 0); - let updateResult = recordArray.update(); + const updateResult = recordArray.update(); assert.strictEqual(queryCalled, 1); const expectedResult = []; @@ -109,26 +109,26 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR let contentDidChange = 0; this.owner.register('model:tag', Tag); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let manager = new RecordArrayManager({ + const manager = new RecordArrayManager({ store, }); - let recordArray = new AdapterPopulatedRecordArray({ + const recordArray = new AdapterPopulatedRecordArray({ query: 'some-query', manager, identifiers: [], store, }); - let model1 = { + const model1 = { type: 'tag', id: '1', attributes: { name: 'Scumbag Dale', }, }; - let model2 = { + const model2 = { type: 'tag', id: '2', attributes: { @@ -173,14 +173,14 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR arrayDidChange = 0; contentDidChange = 0; - let model3 = { + const model3 = { type: 'tag', id: '3', attributes: { name: 'Scumbag Penner', }, }; - let model4 = { + const model4 = { type: 'tag', id: '4', attributes: { @@ -224,7 +224,7 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR assert.strictEqual(arrayDidChange, 0, 'record array should not yet have omitted a change event'); assert.strictEqual(contentDidChange, 0, 'recordArray.content should not have changed'); - let model5 = { + const model5 = { type: 'tag', id: '5', attributes: { diff --git a/tests/main/tests/unit/record-arrays/record-array-test.js b/tests/main/tests/unit/record-arrays/record-array-test.js index b11d4722627..efaa640bed4 100644 --- a/tests/main/tests/unit/record-arrays/record-array-test.js +++ b/tests/main/tests/unit/record-arrays/record-array-test.js @@ -18,7 +18,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { setupTest(hooks); test('default initial state', async function (assert) { - let recordArray = new RecordArray({ type: 'recordType', identifiers: [], store: null }); + const recordArray = new RecordArray({ type: 'recordType', identifiers: [], store: null }); assert.false(recordArray.isUpdating, 'record is not updating'); assert.strictEqual(recordArray.modelName, 'recordType', 'has modelName'); @@ -27,8 +27,8 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { }); test('custom initial state', async function (assert) { - let store = {}; - let recordArray = new RecordArray({ + const store = {}; + const recordArray = new RecordArray({ type: 'apple', identifiers: [], store, @@ -40,7 +40,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { }); testInDebug('Mutation throws error', async function (assert) { - let recordArray = new RecordArray({ identifiers: [], type: 'recordType' }); + const recordArray = new RecordArray({ identifiers: [], type: 'recordType' }); assert.throws( () => { @@ -53,9 +53,9 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { test('#access by index', async function (assert) { this.owner.register('model:tag', Tag); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let records = store.push({ + const records = store.push({ data: [ { type: 'tag', @@ -72,7 +72,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { ], }); - let recordArray = new RecordArray({ + const recordArray = new RecordArray({ type: 'recordType', identifiers: records.map(recordIdentifierFor), store, @@ -87,7 +87,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { test('#update', async function (assert) { let findAllCalled = 0; - let deferred = createDeferred(); + const deferred = createDeferred(); const store = { findAll(modelName, options) { @@ -98,7 +98,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { }, }; - let recordArray = new RecordArray({ + const recordArray = new RecordArray({ type: 'recordType', identifiers: [], store, @@ -108,7 +108,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { assert.strictEqual(findAllCalled, 0); - let updateResult = recordArray.update(); + const updateResult = recordArray.update(); assert.strictEqual(findAllCalled, 1); @@ -124,7 +124,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { test('#update while updating', async function (assert) { let findAllCalled = 0; - let deferred = createDeferred(); + const deferred = createDeferred(); const store = { findAll(modelName, options) { findAllCalled++; @@ -132,7 +132,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { }, }; - let recordArray = new RecordArray({ + const recordArray = new RecordArray({ type: 'recordType', identifiers: [], store, @@ -141,11 +141,11 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { assert.false(recordArray.isUpdating, 'should not be updating'); assert.strictEqual(findAllCalled, 0); - let updateResult1 = recordArray.update(); + const updateResult1 = recordArray.update(); assert.strictEqual(findAllCalled, 1); - let updateResult2 = recordArray.update(); + const updateResult2 = recordArray.update(); assert.strictEqual(findAllCalled, 1); @@ -163,22 +163,22 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { test('#save', async function (assert) { this.owner.register('model:tag', Tag); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let model1 = { + const model1 = { id: '1', type: 'tag', }; - let model2 = { + const model2 = { id: '2', type: 'tag', }; - let [record1, record2] = store.push({ + const [record1, record2] = store.push({ data: [model1, model2], }); - let identifiers = [recordIdentifierFor(record1), recordIdentifierFor(record2)]; - let recordArray = new RecordArray({ + const identifiers = [recordIdentifierFor(record1), recordIdentifierFor(record2)]; + const recordArray = new RecordArray({ identifiers, store, }); @@ -193,7 +193,7 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { assert.strictEqual(model1Saved, 0, 'save not yet called'); assert.strictEqual(model2Saved, 0, 'save not yet called'); - let result = recordArray.save(); + const result = recordArray.save(); assert.strictEqual(model1Saved, 1, 'save was called for model1'); assert.strictEqual(model2Saved, 1, 'save was called for mode2'); @@ -207,12 +207,12 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { const store = this.owner.lookup('service:store'); store._fetchManager = new FetchManager(store); - let model1 = { + const model1 = { id: '1', type: 'tag', }; - let model2 = { + const model2 = { id: '2', type: 'tag', }; @@ -220,8 +220,8 @@ module('unit/record-arrays/record-array - DS.RecordArray', function (hooks) { data: [model1, model2], }); - let snapshot = new SnapshotRecordArray(store, 'tag', {}); - let [snapshot1, snapshot2] = snapshot.snapshots(); + const snapshot = new SnapshotRecordArray(store, 'tag', {}); + const [snapshot1, snapshot2] = snapshot.snapshots(); assert.strictEqual( snapshot1.id, diff --git a/tests/main/tests/unit/store/adapter-interop-test.js b/tests/main/tests/unit/store/adapter-interop-test.js index 986ff960c7d..80c50987b47 100644 --- a/tests/main/tests/unit/store/adapter-interop-test.js +++ b/tests/main/tests/unit/store/adapter-interop-test.js @@ -16,7 +16,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho test('Calling Store#find invokes its adapter#find', async function (assert) { assert.expect(5); - let currentStore = this.owner.lookup('service:store'); + const currentStore = this.owner.lookup('service:store'); const ApplicationAdapter = Adapter.extend({ findRecord(store, type, id, snapshot) { @@ -70,7 +70,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('serializer:application', class extends JSONAPISerializer {}); this.owner.register('model:test', Model.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await Promise.all([store.findRecord('test', '1'), store.findRecord('test', '2')]); }); @@ -130,7 +130,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('serializer:application', class extends JSONAPISerializer {}); this.owner.register('model:test', Model.extend()); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await Promise.all( Object.keys(includedResourcesForIds).map((id) => @@ -152,7 +152,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('serializer:application', class extends JSONAPISerializer {}); this.owner.register('model:test', Model.extend({ name: attr() })); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findRecord('test', '1').then((object) => { assert.strictEqual(object.name, 'Scumbag Dale', 'the data was pushed'); @@ -173,7 +173,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('serializer:application', class extends JSONAPISerializer {}); this.owner.register('model:test', Model.extend({ name: attr() })); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store .findRecord('test', 1) @@ -218,7 +218,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -250,7 +250,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho test('loadMany takes an optional Object and passes it on to the Adapter', async function (assert) { assert.expect(2); - let passedQuery = { page: 1 }; + const passedQuery = { page: 1 }; const Person = Model.extend({ name: attr('string'), @@ -268,13 +268,13 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.query('person', passedQuery); }); test('Find with query calls the correct normalizeResponse', async function (assert) { - let passedQuery = { page: 1 }; + const passedQuery = { page: 1 }; let callCount = 0; const Person = Model.extend({ @@ -298,7 +298,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', ApplicationSerializer); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.query('person', passedQuery); @@ -313,7 +313,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('model:person', Person); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -325,7 +325,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }, }); - let results = store.peekAll('person'); + const results = store.peekAll('person'); assert.strictEqual(results.length, 1, 'record array should have the original object'); assert.strictEqual(results.at(0).name, 'Tom Dale', 'record has the correct information'); @@ -353,7 +353,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('model:person', Person); - let person = this.owner.lookup('service:store').createRecord('person'); + const person = this.owner.lookup('service:store').createRecord('person'); assert.true(person.isLoaded, 'A newly created record is loaded'); assert.true(person.isNew, 'A newly created record is new'); @@ -373,7 +373,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.createRecord('person', { id: '5' }); @@ -390,8 +390,8 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('model:person', Person); - let store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { name: 'Brohuda Katz' }); + const store = this.owner.lookup('service:store'); + const person = store.createRecord('person', { name: 'Brohuda Katz' }); assert.true(person.isLoaded, 'A newly created record is loaded'); assert.true(person.isNew, 'A newly created record is new'); @@ -414,9 +414,9 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('model:person', Person); this.owner.register('adapter:application', ApplicationAdapter); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.createRecord('person', { id: '1', name: 'Brohuda Katz' }); + const person = store.createRecord('person', { id: '1', name: 'Brohuda Katz' }); await store.findRecord('person', '1').then((again) => { assert.strictEqual(person, again, 'the store returns the loaded object'); @@ -441,7 +441,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findRecord('test', '1', { preload: { name: 'Test' } }); }); @@ -465,7 +465,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -477,7 +477,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }, }); - let tom = store.peekRecord('person', 2); + const tom = store.peekRecord('person', 2); await store.findRecord('person', 1, { preload: { friend: tom } }); }); @@ -499,7 +499,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findRecord('person', '1', { preload: { friend: '2' } }).then(() => { return store.peekRecord('person', '1').friend.then((friend) => { @@ -527,7 +527,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -539,7 +539,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }, }); - let tom = store.peekRecord('person', '2'); + const tom = store.peekRecord('person', '2'); await store.findRecord('person', '1', { preload: { friends: [tom] } }); }); @@ -562,7 +562,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findRecord('person', '1', { preload: { friends: ['2'] } }); }); @@ -586,12 +586,12 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findRecord('person', '1', { preload: { friends: [] } }); }); - test('initial values of hasMany can be passed in as the third argument to find as ids', async function (assert) { + test('initial values of hasMany can be passed in as the third argument to find as ids, v2', async function (assert) { assert.expect(1); const Person = Model.extend({ @@ -610,7 +610,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findRecord('person', '1', { preload: { friends: [] } }); }); @@ -641,11 +641,11 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let people = store.peekAll('person'); - let tom = store.createRecord('person', { name: 'Tom Dale' }); - let yehuda = store.createRecord('person', { name: 'Yehuda Katz' }); + const people = store.peekAll('person'); + const tom = store.createRecord('person', { name: 'Tom Dale' }); + const yehuda = store.createRecord('person', { name: 'Yehuda Katz' }); await Promise.all([tom.save(), yehuda.save()]).then(() => { people.forEach((person, index) => { @@ -668,7 +668,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }, findMany(store, type, ids, snapshots) { - let records = ids.map((id) => ({ id, type: 'test' })); + const records = ids.map((id) => ({ id, type: 'test' })); assert.deepEqual(ids, ['20', '21'], 'The second group is passed to findMany'); @@ -680,9 +680,9 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let identifiers = [ + const identifiers = [ store.identifierCache.getOrCreateRecordIdentifier({ type: 'test', id: '10' }), store.identifierCache.getOrCreateRecordIdentifier({ type: 'test', id: '20' }), store.identifierCache.getOrCreateRecordIdentifier({ type: 'test', id: '21' }), @@ -690,7 +690,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho const result = await Promise.all(identifiers.map((id) => store.findRecord(id))); - let ids = result.map((x) => x.id); + const ids = result.map((x) => x.id); assert.deepEqual(ids, ['10', '20', '21'], 'The promise fulfills with the identifiers'); }); @@ -705,7 +705,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }, findRecord(store, type, id, snapshot) { - let record = { id, type: 'test' }; + const record = { id, type: 'test' }; return new Promise(function (resolve, reject) { if (id === 'igor') { @@ -724,11 +724,11 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('serializer:application', class extends JSONAPISerializer {}); this.owner.register('adapter:application', ApplicationAdapter); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let david = store.findRecord('test', 'david'); - let igor = store.findRecord('test', 'igor'); - let wait = []; + const david = store.findRecord('test', 'david'); + const igor = store.findRecord('test', 'igor'); + const wait = []; wait.push( igor.then(() => { @@ -756,7 +756,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho }, findRecord(store, type, id, snapshot) { - let record = { id, type: 'test' }; + const record = { id, type: 'test' }; return new Promise((resolve, reject) => { if (id === 'igor') { @@ -775,11 +775,11 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('serializer:application', class extends JSONAPISerializer {}); this.owner.register('adapter:application', ApplicationAdapter); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let david = store.findRecord('test', 'david'); - let igor = store.findRecord('test', 'igor'); - let wait = []; + const david = store.findRecord('test', 'david'); + const igor = store.findRecord('test', 'igor'); + const wait = []; wait.push( igor.catch(() => { @@ -803,7 +803,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho const ApplicationAdapter = Adapter.extend({ findMany(store, type, ids, snapshots) { - let records = ids.map((id) => ({ id, type: 'test' })); + const records = ids.map((id) => ({ id, type: 'test' })); return { data: [records[0]] }; }, }); @@ -812,11 +812,11 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await assert.expectWarning(async () => { - let david = store.findRecord('test', 'david'); - let igor = store.findRecord('test', 'igor'); + const david = store.findRecord('test', 'david'); + const igor = store.findRecord('test', 'igor'); try { await Promise.all([david, igor]); @@ -835,7 +835,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho assert.expect(3); const ApplicationAdapter = Adapter.extend({ findMany(store, type, ids, snapshots) { - let records = ids.map((id) => ({ id, type: 'test' })).filter(({ id }) => id === 'david'); + const records = ids.map((id) => ({ id, type: 'test' })).filter(({ id }) => id === 'david'); return { data: [records[0]] }; }, @@ -845,13 +845,13 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); let igorDidReject = true; await assert.expectWarning( async () => { - let wait = []; + const wait = []; wait.push(store.findRecord('test', 'david')); wait.push( store.findRecord('test', 'igor').catch((e) => { @@ -892,7 +892,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findRecord('person', '1'); }); @@ -917,7 +917,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -947,7 +947,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -985,7 +985,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -1017,7 +1017,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: { @@ -1055,7 +1055,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); const record = store.push({ data: { @@ -1090,7 +1090,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findAll('person'); }); @@ -1117,7 +1117,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findAll('person').then((records) => { assert.strictEqual(records.at(0).name, 'Tom'); @@ -1148,7 +1148,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findAll('person').then((records) => { assert.strictEqual(records[0].name, 'Tom'); @@ -1177,7 +1177,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); await store.findAll('person').then((records) => { assert.strictEqual(records.at(0), undefined); @@ -1214,7 +1214,7 @@ module('unit/store/adapter-interop - Store working with a Adapter', function (ho this.owner.register('adapter:application', ApplicationAdapter); this.owner.register('serializer:application', class extends JSONAPISerializer {}); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [{ id: '1', type: 'person', attributes: { name: 'John' } }] }); diff --git a/tests/main/tests/unit/store/asserts-test.js b/tests/main/tests/unit/store/asserts-test.js index 981a37260af..68eda1dc9f0 100644 --- a/tests/main/tests/unit/store/asserts-test.js +++ b/tests/main/tests/unit/store/asserts-test.js @@ -11,7 +11,7 @@ import test from '@ember-data/unpublished-test-infra/test-support/test-in-debug' module('unit/store/asserts - Store methods produce useful assertion messages', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let { owner } = this; + const { owner } = this; owner.register('model:foo', class extends Model {}); }); diff --git a/tests/main/tests/unit/store/create-record-test.js b/tests/main/tests/unit/store/create-record-test.js index df8e0686838..a09c9d7a5ec 100644 --- a/tests/main/tests/unit/store/create-record-test.js +++ b/tests/main/tests/unit/store/create-record-test.js @@ -69,8 +69,8 @@ module('unit/store/createRecord - Store creating records', function (hooks) { this.owner.register('model:comment', Comment); this.owner.register('model:author', Author); - let store = this.owner.lookup('service:store'); - let comment = store.push({ + const store = this.owner.lookup('service:store'); + const comment = store.push({ data: { type: 'comment', id: '1', @@ -79,7 +79,7 @@ module('unit/store/createRecord - Store creating records', function (hooks) { }, }, }); - let author = store.push({ + const author = store.push({ data: { type: 'author', id: '1', @@ -89,13 +89,13 @@ module('unit/store/createRecord - Store creating records', function (hooks) { }, }); - let properties = { + const properties = { title: 'My Post', randomProp: 'An unknown prop', comments: [comment], author, }; - let propertiesClone = { + const propertiesClone = { title: 'My Post', randomProp: 'An unknown prop', comments: [comment], @@ -120,7 +120,7 @@ module('unit/store/createRecord - Store creating records', function (hooks) { this.owner.register('model:record', Record); this.owner.register('model:storage', Storage); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -141,8 +141,8 @@ module('unit/store/createRecord - Store creating records', function (hooks) { ], }); - let records = store.peekAll('record').slice(); - let storage = store.createRecord('storage', { name: 'Great store', records: records }); + const records = store.peekAll('record').slice(); + const storage = store.createRecord('storage', { name: 'Great store', records: records }); assert.strictEqual(storage.name, 'Great store', 'The attribute is well defined'); assert.strictEqual( @@ -168,9 +168,9 @@ module('unit/store/createRecord - Store with models by dash', function (hooks) { this.owner.register('model:some-thing', SomeThing); - let store = this.owner.lookup('service:store'); - let attributes = { foo: 'bar' }; - let record = store.createRecord('some-thing', attributes); + const store = this.owner.lookup('service:store'); + const attributes = { foo: 'bar' }; + const record = store.createRecord('some-thing', attributes); assert.strictEqual(record.foo, attributes.foo, 'The record is created'); assert.strictEqual(store.modelFor('some-thing').modelName, 'some-thing'); diff --git a/tests/main/tests/unit/store/finders-test.js b/tests/main/tests/unit/store/finders-test.js index 272246cf43e..ce37f161cda 100644 --- a/tests/main/tests/unit/store/finders-test.js +++ b/tests/main/tests/unit/store/finders-test.js @@ -35,7 +35,7 @@ module('unit/store/finders', function (hooks) { test('findRecord does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = createDeferred(); + const deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -45,7 +45,7 @@ module('unit/store/finders', function (hooks) { ); let serializerLoaded = false; - let serializerFor = this.store.serializerFor; + const serializerFor = this.store.serializerFor; this.store.serializerFor = (modelName) => { if (modelName === 'person') { serializerLoaded = true; @@ -53,7 +53,7 @@ module('unit/store/finders', function (hooks) { return serializerFor.call(this.store, modelName); }; - let storePromise = this.store.findRecord('person', 1); + const storePromise = this.store.findRecord('person', 1); assert.false(serializerLoaded, 'serializer is not eagerly loaded'); deferedFind.resolve({ @@ -68,7 +68,7 @@ module('unit/store/finders', function (hooks) { test('findMany does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = createDeferred(); + const deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -78,7 +78,7 @@ module('unit/store/finders', function (hooks) { ); let serializerLoaded = false; - let serializerFor = this.store.serializerFor; + const serializerFor = this.store.serializerFor; this.store.serializerFor = (modelName) => { if (modelName === 'person') { serializerLoaded = true; @@ -87,7 +87,7 @@ module('unit/store/finders', function (hooks) { }; this.store.findRecord('person', 1); - let storePromise = this.store.findRecord('person', 2); + const storePromise = this.store.findRecord('person', 2); assert.false(serializerLoaded, 'serializer is not eagerly loaded'); @@ -106,7 +106,7 @@ module('unit/store/finders', function (hooks) { test('findHasMany does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = createDeferred(); + const deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -116,7 +116,7 @@ module('unit/store/finders', function (hooks) { ); let serializerLoaded = false; - let serializerFor = this.store.serializerFor; + const serializerFor = this.store.serializerFor; this.store.serializerFor = (modelName) => { if (modelName === 'dog') { serializerLoaded = true; @@ -141,7 +141,7 @@ module('unit/store/finders', function (hooks) { }, }); - let storePromise = this.store.peekRecord('person', 1).dogs; + const storePromise = this.store.peekRecord('person', 1).dogs; assert.false(serializerLoaded, 'serializer is not eagerly loaded'); deferedFind.resolve({ @@ -159,7 +159,7 @@ module('unit/store/finders', function (hooks) { test('findBelongsTo does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = createDeferred(); + const deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -169,7 +169,7 @@ module('unit/store/finders', function (hooks) { ); let serializerLoaded = false; - let serializerFor = this.store.serializerFor; + const serializerFor = this.store.serializerFor; this.store.serializerFor = (modelName) => { if (modelName === 'dog') { serializerLoaded = true; @@ -194,7 +194,7 @@ module('unit/store/finders', function (hooks) { }, }); - let storePromise = this.store.peekRecord('person', 1).favoriteDog; + const storePromise = this.store.peekRecord('person', 1).favoriteDog; assert.false(serializerLoaded, 'serializer is not eagerly loaded'); @@ -208,7 +208,7 @@ module('unit/store/finders', function (hooks) { test('findAll does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = createDeferred(); + const deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -218,7 +218,7 @@ module('unit/store/finders', function (hooks) { ); let serializerLoaded = false; - let serializerFor = this.store.serializerFor; + const serializerFor = this.store.serializerFor; this.store.serializerFor = (modelName) => { if (modelName === 'person') { serializerLoaded = true; @@ -226,7 +226,7 @@ module('unit/store/finders', function (hooks) { return serializerFor.call(this.store, modelName); }; - let storePromise = this.store.findAll('person'); + const storePromise = this.store.findAll('person'); assert.false(serializerLoaded, 'serializer is not eagerly loaded'); deferedFind.resolve({ @@ -241,7 +241,7 @@ module('unit/store/finders', function (hooks) { test('query does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = createDeferred(); + const deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -251,7 +251,7 @@ module('unit/store/finders', function (hooks) { ); let serializerLoaded = false; - let serializerFor = this.store.serializerFor; + const serializerFor = this.store.serializerFor; this.store.serializerFor = (modelName) => { if (modelName === 'person') { serializerLoaded = true; @@ -259,7 +259,7 @@ module('unit/store/finders', function (hooks) { return serializerFor.call(this.store, modelName); }; - let storePromise = this.store.query('person', { first_duke_of_marlborough: true }); + const storePromise = this.store.query('person', { first_duke_of_marlborough: true }); assert.false(serializerLoaded, 'serializer is not eagerly loaded'); deferedFind.resolve({ @@ -274,7 +274,7 @@ module('unit/store/finders', function (hooks) { test('queryRecord does not load a serializer until the adapter promise resolves', async function (assert) { assert.expect(2); - let deferedFind = createDeferred(); + const deferedFind = createDeferred(); this.owner.register( 'adapter:person', @@ -284,7 +284,7 @@ module('unit/store/finders', function (hooks) { ); let serializerLoaded = false; - let serializerFor = this.store.serializerFor; + const serializerFor = this.store.serializerFor; this.store.serializerFor = (modelName) => { if (modelName === 'person') { serializerLoaded = true; @@ -292,7 +292,7 @@ module('unit/store/finders', function (hooks) { return serializerFor.call(this.store, modelName); }; - let storePromise = this.store.queryRecord('person', { first_duke_of_marlborough: true }); + const storePromise = this.store.queryRecord('person', { first_duke_of_marlborough: true }); assert.false(serializerLoaded, 'serializer is not eagerly loaded'); deferedFind.resolve({ diff --git a/tests/main/tests/unit/store/model-for-test.js b/tests/main/tests/unit/store/model-for-test.js index 53bae338b56..cb817bedb0a 100644 --- a/tests/main/tests/unit/store/model-for-test.js +++ b/tests/main/tests/unit/store/model-for-test.js @@ -16,8 +16,8 @@ module('unit/store/model_for - DS.Store#modelFor', function (hooks) { }); test('when fetching factory from string, sets a normalized key as modelName', function (assert) { - let store = this.owner.lookup('service:store'); - let { __registry__: registry } = this.owner; + const store = this.owner.lookup('service:store'); + const { __registry__: registry } = this.owner; registry.normalize = (key) => dasherize(camelize(key)); @@ -26,8 +26,8 @@ module('unit/store/model_for - DS.Store#modelFor', function (hooks) { }); test('when fetching factory from string and dashing normalizer, sets a normalized key as modelName', function (assert) { - let store = this.owner.lookup('service:store'); - let { __registry__: registry } = this.owner; + const store = this.owner.lookup('service:store'); + const { __registry__: registry } = this.owner; registry.normalize = (key) => dasherize(camelize(key)); @@ -36,7 +36,7 @@ module('unit/store/model_for - DS.Store#modelFor', function (hooks) { }); testInDebug(`when fetching something that doesn't exist, throws error`, function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.throws(() => { store.modelFor('wild-stuff'); diff --git a/tests/main/tests/unit/store/peek-record-test.js b/tests/main/tests/unit/store/peek-record-test.js index bd784922b52..ab8aef32746 100644 --- a/tests/main/tests/unit/store/peek-record-test.js +++ b/tests/main/tests/unit/store/peek-record-test.js @@ -16,9 +16,9 @@ module('unit/store/peekRecord - Store peekRecord', function (hooks) { }); test('peekRecord should return the record if it is in the store', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -32,9 +32,9 @@ module('unit/store/peekRecord - Store peekRecord', function (hooks) { }); test('peekRecord should return the record with identifier as argument', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -48,7 +48,7 @@ module('unit/store/peekRecord - Store peekRecord', function (hooks) { }); test('peekRecord should return null if the record is not in the store ', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.strictEqual( store.peekRecord('person', 1), @@ -58,7 +58,7 @@ module('unit/store/peekRecord - Store peekRecord', function (hooks) { }); testInDebug('peekRecord should assert if not passed both model name and id', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.expectAssertion(() => { store.peekRecord('my-id'); @@ -66,10 +66,10 @@ module('unit/store/peekRecord - Store peekRecord', function (hooks) { }); testInDebug('peekRecord should assert if passed a model class instead of model name', function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); assert.expectAssertion(() => { - let modelClass = EmberObject.extend(); + const modelClass = EmberObject.extend(); store.peekRecord(modelClass, 'id'); }, /Passing classes to store methods has been removed/); }); @@ -90,7 +90,7 @@ module('unit/store/peekRecord - Store peekRecord', function (hooks) { { withType: true, withLid: true, extra: { id: null }, desc: 'type, null id, and lid' }, ].forEach(({ withType, withId, withLid, extra, isCreate, desc }) => { test(`peekRecord (${desc})`, function (assert) { - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); let person; if (isCreate) { diff --git a/tests/main/tests/unit/store/push-test.js b/tests/main/tests/unit/store/push-test.js index 6c32cd87c63..42c64aa0643 100644 --- a/tests/main/tests/unit/store/push-test.js +++ b/tests/main/tests/unit/store/push-test.js @@ -31,7 +31,7 @@ module('unit/store/push - Store#push', function (hooks) { test('Changed attributes are reset when matching data is pushed', function (assert) { const store = this.owner.lookup('service:store'); - let person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -79,11 +79,11 @@ module('unit/store/push - Store#push', function (hooks) { assert.expect(2); const store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; - let person = store.push({ + const person = store.push({ data: { type: 'person', id: 'wat', @@ -112,7 +112,7 @@ module('unit/store/push - Store#push', function (hooks) { assert.expect(2); const store = this.owner.lookup('service:store'); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); adapter.shouldBackgroundReloadRecord = () => false; @@ -127,7 +127,7 @@ module('unit/store/push - Store#push', function (hooks) { }, }); - let person = store.peekRecord('person', 'wat'); + const person = store.peekRecord('person', 'wat'); store.push({ data: { @@ -155,10 +155,9 @@ module('unit/store/push - Store#push', function (hooks) { test('Calling push on normalize allows partial updates with raw JSON', function (assert) { this.owner.register('serializer:person', RESTSerializer); - let person; const store = this.owner.lookup('service:store'); - person = store.push({ + const person = store.push({ data: { type: 'person', id: '1', @@ -192,7 +191,7 @@ module('unit/store/push - Store#push', function (hooks) { } this.owner.register('model:person', Person); - let adapter = store.adapterFor('application'); + const adapter = store.adapterFor('application'); adapter.findRecord = function (store, type, id) { if (id === '1') { @@ -226,7 +225,7 @@ module('unit/store/push - Store#push', function (hooks) { } }; - let normalized = store.normalize('person', { + const normalized = store.normalize('person', { id: 'wat', type: 'person', attributes: { @@ -242,10 +241,10 @@ module('unit/store/push - Store#push', function (hooks) { }, }, }); - let person = store.push(normalized); + const person = store.push(normalized); await person.phoneNumbers.then((phoneNumbers) => { - let items = phoneNumbers.map((item) => { + const items = phoneNumbers.map((item) => { return item ? item.getProperties('id', 'number', 'person') : null; }); assert.deepEqual(items, [ @@ -265,7 +264,7 @@ module('unit/store/push - Store#push', function (hooks) { testInDebug('calling push without data argument as an object raises an error', function (assert) { const store = this.owner.lookup('service:store'); - let invalidValues = [null, 1, 'string', class {}, true]; + const invalidValues = [null, 1, 'string', class {}, true]; assert.expect(invalidValues.length + 1); @@ -354,7 +353,7 @@ module('unit/store/push - Store#push', function (hooks) { ], }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); assert.strictEqual(person.phoneNumbers.length, 1); assert.strictEqual(person.phoneNumbers.at(0).number, '1-800-DATA'); @@ -418,7 +417,7 @@ module('unit/store/push - Store#push', function (hooks) { }) ); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); assert.strictEqual(person.firstName, 'Tan', 'you can use links containing an object'); }); @@ -442,7 +441,7 @@ module('unit/store/push - Store#push', function (hooks) { }) ); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); assert.strictEqual(person.firstName, 'Tan', 'you can use links that contain null as a value'); }); @@ -468,7 +467,7 @@ module('unit/store/push - Store#push', function (hooks) { this.owner.register('model:user', class extends Model {}); const store = this.owner.lookup('service:store'); - let invalidValues = [{ type: 'user' }, { id: null, type: 'user' }, { id: '', type: 'user' }]; + const invalidValues = [{ type: 'user' }, { id: null, type: 'user' }, { id: '', type: 'user' }]; assert.expect(invalidValues.length); @@ -517,7 +516,7 @@ module('unit/store/push - Store#push', function (hooks) { test('_push returns an identifier if an object is pushed', function (assert) { const store = this.owner.lookup('service:store'); - let pushResult = store._push({ + const pushResult = store._push({ data: { id: '1', type: 'person', @@ -530,7 +529,7 @@ module('unit/store/push - Store#push', function (hooks) { test('_push does not require a modelName to resolve to a modelClass', function (assert) { const store = this.owner.lookup('service:store'); - let originalCall = store.modelFor; + const originalCall = store.modelFor; store.modelFor = function () { assert.notOk('modelFor was triggered as a result of a call to store._push'); }; @@ -548,7 +547,7 @@ module('unit/store/push - Store#push', function (hooks) { test('_push returns an array of identifiers if an array is pushed', function (assert) { const store = this.owner.lookup('service:store'); - let pushResult = store._push({ + const pushResult = store._push({ data: [ { id: '1', @@ -564,7 +563,7 @@ module('unit/store/push - Store#push', function (hooks) { test('_push returns null if no data is pushed', function (assert) { const store = this.owner.lookup('service:store'); - let pushResult = store._push({ + const pushResult = store._push({ data: null, }); @@ -593,7 +592,7 @@ module('unit/store/push - Store#pushPayload', function (hooks) { ], }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); assert.strictEqual(post.postTitle, 'Ember rocks', 'you can push raw JSON into the store'); @@ -619,7 +618,7 @@ module('unit/store/push - Store#pushPayload', function (hooks) { }, }); - let post = store.peekRecord('post', 1); + const post = store.peekRecord('post', 1); assert.strictEqual(post.postTitle, 'Ember rocks', 'you can push raw JSON into the store'); @@ -678,11 +677,11 @@ module('unit/store/push - Store#pushPayload', function (hooks) { ], }); - let post = store.peekRecord('post', '1'); + const post = store.peekRecord('post', '1'); assert.strictEqual(post.postTitle, 'Ember rocks', 'you can push raw JSON into the store'); - let person = store.peekRecord('person', '2'); + const person = store.peekRecord('person', '2'); assert.strictEqual(person.firstName, 'Yehuda', 'you can push raw JSON into the store'); }); @@ -781,7 +780,7 @@ module('unit/store/push - Store#pushPayload', function (hooks) { ], }); - let person = store.peekRecord('person', 1); + const person = store.peekRecord('person', 1); assert.strictEqual(person.firstName, 'Robert', 'you can push raw JSON into the store'); assert.strictEqual(person.lastName, 'Jackson', 'you can push raw JSON into the store'); @@ -868,7 +867,7 @@ module('unit/store/push - Store#pushPayload', function (hooks) { ], }); - let robert = store.peekRecord('person', '1'); + const robert = store.peekRecord('person', '1'); const friends = robert.friends; assert.strictEqual(friends.at(0).id, '2', 'first object is unchanged'); @@ -922,10 +921,10 @@ module('unit/store/push - Store#push with JSON-API', function (hooks) { ], }); - let tom = store.peekRecord('person', 1); + const tom = store.peekRecord('person', 1); assert.strictEqual(tom.name, 'Tom Dale', 'Tom should be in the store'); - let tomster = store.peekRecord('person', 2); + const tomster = store.peekRecord('person', 2); assert.strictEqual(tomster.name, 'Tomster', 'Tomster should be in the store'); }); @@ -973,10 +972,10 @@ module('unit/store/push - Store#push with JSON-API', function (hooks) { ], }); - let tomster = store.peekRecord('person', 1); + const tomster = store.peekRecord('person', 1); assert.strictEqual(tomster.name, 'Tomster', 'Tomster should be in the store'); - let car = store.peekRecord('car', 1); + const car = store.peekRecord('car', 1); assert.strictEqual(car.model, 'Neon', "Tomster's car should be in the store"); }); }); diff --git a/tests/main/tests/unit/store/unload-test.js b/tests/main/tests/unit/store/unload-test.js index d5bb00b1253..98dc25ecbe3 100644 --- a/tests/main/tests/unit/store/unload-test.js +++ b/tests/main/tests/unit/store/unload-test.js @@ -16,7 +16,7 @@ module('unit/store/unload - Store unloading records', function (hooks) { setupTest(hooks); hooks.beforeEach(function () { - let Record = Model.extend({ + const Record = Model.extend({ title: attr('string'), wasFetched: attr('boolean'), }); @@ -42,7 +42,7 @@ module('unit/store/unload - Store unloading records', function (hooks) { testInDebug('unload an in-flight record asserts', async function (assert) { assert.expect(2); - let record = store.push({ + const record = store.push({ data: { type: 'record', id: '1', @@ -63,7 +63,7 @@ module('unit/store/unload - Store unloading records', function (hooks) { record.set('title', 'toto2'); assert.strictEqual(get(record, 'hasDirtyAttributes'), true, 'record is dirty'); - let promise = record.save(); + const promise = record.save(); assert.expectAssertion( function () { @@ -103,12 +103,12 @@ module('unit/store/unload - Store unloading records', function (hooks) { }); test('unload followed by create of the same type + id', async function (assert) { - let record = store.createRecord('record', { id: '1' }); + const record = store.createRecord('record', { id: '1' }); assert.strictEqual(store.peekRecord('record', 1), record, 'record should exactly equal'); record.unloadRecord(); - let createdRecord = store.createRecord('record', { id: '1' }); + const createdRecord = store.createRecord('record', { id: '1' }); assert.notStrictEqual(record, createdRecord, 'newly created record is fresh (and was created)'); }); }); @@ -169,7 +169,7 @@ module('Store - unload record with relationships', function (hooks) { }) ); - let store = this.owner.lookup('service:store'); + const store = this.owner.lookup('service:store'); store.push({ data: [ @@ -196,7 +196,7 @@ module('Store - unload record with relationships', function (hooks) { }); let product = store.peekRecord('product', 1); - let like = store.createRecord('like', { id: '1', product: product }); + const like = store.createRecord('like', { id: '1', product: product }); await like.save(); diff --git a/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js b/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js index 78c170640b7..803fd2a63da 100644 --- a/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js +++ b/tests/main/tests/unit/system/relationships/polymorphic-relationship-payloads-test.js @@ -68,11 +68,11 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('push one side is polymorphic, subType then baseType', function (assert) { - let User = Model.extend({ + const User = Model.extend({ hats: hasMany('hat', { async: false, polymorphic: true, inverse: 'user' }), }); - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), user: belongsTo('user', { async: false, inverse: 'hats', as: 'hat' }), }); @@ -123,11 +123,11 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('push one side is polymorphic, different subtypes', function (assert) { - let User = Model.extend({ + const User = Model.extend({ hats: hasMany('hat', { async: false, polymorphic: true, inverse: 'user' }), }); - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), user: belongsTo('user', { async: false, inverse: 'hats', as: 'hat' }), }); @@ -179,11 +179,11 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('push both sides are polymorphic', function (assert) { - let User = Model.extend({ + const User = Model.extend({ hats: hasMany('hat', { async: false, polymorphic: true, as: 'user', inverse: 'user' }), }); - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), user: belongsTo('user', { async: false, inverse: 'hats', polymorphic: true, as: 'hat' }), }); @@ -234,7 +234,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('handles relationships where both sides are polymorphic', function (assert) { - let Person = Model.extend({ + const Person = Model.extend({ hats: hasMany('hat', { async: false, polymorphic: true, @@ -243,7 +243,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }), }); - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), person: belongsTo('person', { async: false, @@ -318,7 +318,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio if (Array.isArray(b)) { rel.data = b.map((i) => { - let { type, id } = i; + const { type, id } = i; if (recurse === true) { link(i, [a], relationshipName, false); @@ -338,7 +338,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio } } - let Person = Model.extend({ + const Person = Model.extend({ name: attr(), family: hasMany('person', { async: false, polymorphic: true, inverse: 'family', as: 'person' }), twin: belongsTo('person', { async: false, polymorphic: true, inverse: 'twin', as: 'person' }), @@ -412,7 +412,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio if (Array.isArray(b)) { rel.data = b.map((i) => { - let { type, id } = i; + const { type, id } = i; if (recurse === true) { link(i, [a], relationshipName, false); @@ -555,7 +555,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('push polymorphic self-referential circular non-reflexive relationship', function (assert) { - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), hat: belongsTo('hat', { async: false, inverse: 'hats', polymorphic: true, as: 'hat' }), hats: hasMany('hat', { async: false, inverse: 'hat', polymorphic: true, as: 'hat' }), @@ -599,17 +599,17 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('polymorphic hasMany to types with separate id-spaces', function (assert) { - let User = Model.extend({ + const User = Model.extend({ hats: hasMany('hat', { async: false, polymorphic: true, inverse: 'user', as: 'user' }), }); - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), user: belongsTo('user', { async: false, inverse: 'hats', polymorphic: true, as: 'hat' }), }); - let BigHat = Hat.extend({}); - let SmallHat = Hat.extend({}); + const BigHat = Hat.extend({}); + const SmallHat = Hat.extend({}); this.owner.register('model:user', User); this.owner.register('model:hat', Hat); @@ -654,11 +654,11 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('polymorphic hasMany to types with separate id-spaces, from inverse payload', function (assert) { - let User = Model.extend({ + const User = Model.extend({ hats: hasMany('hat', { async: false, polymorphic: true, inverse: 'user', as: 'user' }), }); - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), user: belongsTo('user', { async: false, inverse: 'hats', polymorphic: true, as: 'hat' }), }); @@ -708,7 +708,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }); test('polymorphic hasMany to polymorphic hasMany types with separate id-spaces', function (assert) { - let Person = Model.extend({ + const Person = Model.extend({ hats: hasMany('hat', { async: false, polymorphic: true, @@ -717,7 +717,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }), }); - let Hat = Model.extend({ + const Hat = Model.extend({ type: attr('string'), person: belongsTo('person', { async: false, @@ -819,7 +819,7 @@ module('unit/relationships/relationship-payloads-manager (polymorphic)', functio }) ); - let runInvalidPush = () => { + const runInvalidPush = () => { return this.store.push({ data: { type: 'post', diff --git a/tests/main/tests/unit/system/snapshot-record-array-test.js b/tests/main/tests/unit/system/snapshot-record-array-test.js index 56e12133e9e..2bd81d943f3 100644 --- a/tests/main/tests/unit/system/snapshot-record-array-test.js +++ b/tests/main/tests/unit/system/snapshot-record-array-test.js @@ -11,14 +11,14 @@ module('Unit - snapshot-record-array', function (hooks) { setupTest(hooks); test('constructor', function (assert) { - let array = A([1, 2]); + const array = A([1, 2]); array.content = [1, 2]; - let options = { + const options = { adapterOptions: 'some options', include: 'include me', }; - let snapshot = new SnapshotRecordArray( + const snapshot = new SnapshotRecordArray( { peekAll() { return array; @@ -52,21 +52,21 @@ module('Unit - snapshot-record-array', function (hooks) { }, }); - let options = { + const options = { adapterOptions: 'some options', include: 'include me', }; let didTakeSnapshot = 0; - let snapshotsTaken = []; + const snapshotsTaken = []; const create = store._fetchManager.createSnapshot; store._fetchManager.createSnapshot = function () { didTakeSnapshot++; - let snapshot = create.apply(this, arguments); + const snapshot = create.apply(this, arguments); snapshotsTaken.push(snapshot); return snapshot; }; - let snapshot = new SnapshotRecordArray(store, 'dog', options); + const snapshot = new SnapshotRecordArray(store, 'dog', options); assert.strictEqual(didTakeSnapshot, 0, 'no shapshot should yet be taken'); assert.strictEqual(snapshot.snapshots()[0], snapshotsTaken[0], 'should be correct snapshot'); diff --git a/tests/main/tests/unit/utils/determine-body-promise-test.js b/tests/main/tests/unit/utils/determine-body-promise-test.js index a5f3579ee7b..d377ab7a313 100644 --- a/tests/main/tests/unit/utils/determine-body-promise-test.js +++ b/tests/main/tests/unit/utils/determine-body-promise-test.js @@ -73,7 +73,7 @@ module('Unit | determineBodyPromise', function () { }); }); - test('determineBodyResponse returns undefined when the http status code is 204', function (assert) { + test('determineBodyResponse returns undefined when the http status code is 204 and response is "null"', function (assert) { assert.expect(1); const response = new Response('null', { status: 204 }); @@ -84,7 +84,7 @@ module('Unit | determineBodyPromise', function () { }); }); - test('determineBodyResponse returns undefined when the http status code is 205', function (assert) { + test('determineBodyResponse returns undefined when the http status code is 205 and response is "null"', function (assert) { assert.expect(1); const response = new Response('null', { status: 205 }); @@ -95,7 +95,7 @@ module('Unit | determineBodyPromise', function () { }); }); - test("determineBodyResponse returns undefined when the request method is 'HEAD'", function (assert) { + test("determineBodyResponse returns undefined when the request method is 'HEAD' and response is 'null'", function (assert) { assert.expect(1); const response = new Response('null', { status: 200 }); diff --git a/tests/main/tests/unit/utils/parse-response-headers-test.js b/tests/main/tests/unit/utils/parse-response-headers-test.js index d9902b35051..d31d82b8abf 100644 --- a/tests/main/tests/unit/utils/parse-response-headers-test.js +++ b/tests/main/tests/unit/utils/parse-response-headers-test.js @@ -7,19 +7,19 @@ const LF = '\u000a'; module('unit/adapters/parse-response-headers', function () { test('returns an NULL Object when headersString is undefined', function (assert) { - let headers = parseResponseHeaders(undefined); + const headers = parseResponseHeaders(undefined); assert.deepEqual(headers, Object.create(null), 'NULL Object is returned'); }); test('header parsing', function (assert) { - let headersString = [ + const headersString = [ 'Content-Encoding: gzip', 'content-type: application/json; charset=utf-8', 'date: Fri, 05 Feb 2016 21:47:56 GMT', ].join(CRLF); - let headers = parseResponseHeaders(headersString); + const headers = parseResponseHeaders(headersString); assert.strictEqual(headers['content-encoding'], 'gzip', 'parses basic header pair'); assert.strictEqual(headers['content-type'], 'application/json; charset=utf-8', 'parses header with complex value'); @@ -27,13 +27,13 @@ module('unit/adapters/parse-response-headers', function () { }); test('field-name parsing', function (assert) { - let headersString = [ + const headersString = [ ' name-with-leading-whitespace: some value', 'name-with-whitespace-before-colon : another value', 'Uppercase-Name: yet another value', ].join(CRLF); - let headers = parseResponseHeaders(headersString); + const headers = parseResponseHeaders(headersString); assert.strictEqual( headers['name-with-leading-whitespace'], @@ -49,14 +49,14 @@ module('unit/adapters/parse-response-headers', function () { }); test('field-value parsing', function (assert) { - let headersString = [ + const headersString = [ 'value-with-leading-space: value with leading whitespace', 'value-without-leading-space:value without leading whitespace', 'value-with-colon: value with: a colon', 'value-with-trailing-whitespace: banana ', ].join(CRLF); - let headers = parseResponseHeaders(headersString); + const headers = parseResponseHeaders(headersString); assert.strictEqual( headers['value-with-leading-space'], @@ -82,11 +82,11 @@ module('unit/adapters/parse-response-headers', function () { ('\r\nfoo: bar'); test('ignores headers that do not contain a colon', function (assert) { - let headersString = ['Content-Encoding: gzip', 'I am ignored because I do not contain a colon', 'apple: pie'].join( + const headersString = ['Content-Encoding: gzip', 'I am ignored because I do not contain a colon', 'apple: pie'].join( CRLF ); - let headers = parseResponseHeaders(headersString); + const headers = parseResponseHeaders(headersString); assert.deepEqual(headers['content-encoding'], 'gzip', 'parses basic header pair'); assert.deepEqual(headers['apple'], 'pie', 'parses basic header pair'); @@ -94,21 +94,21 @@ module('unit/adapters/parse-response-headers', function () { }); test('tollerate extra new-lines', function (assert) { - let headersString = CRLF + 'foo: bar'; - let headers = parseResponseHeaders(headersString); + const headersString = CRLF + 'foo: bar'; + const headers = parseResponseHeaders(headersString); assert.deepEqual(headers['foo'], 'bar', 'parses basic header pair'); assert.strictEqual(Object.keys(headers).length, 1, 'only has the one valid header'); }); test('works with only line feeds', function (assert) { - let headersString = [ + const headersString = [ 'Content-Encoding: gzip', 'content-type: application/json; charset=utf-8', 'date: Fri, 05 Feb 2016 21:47:56 GMT', ].join(LF); - let headers = parseResponseHeaders(headersString); + const headers = parseResponseHeaders(headersString); assert.strictEqual(headers['Content-Encoding'], 'gzip', 'parses basic header pair'); assert.strictEqual(headers['content-type'], 'application/json; charset=utf-8', 'parses header with complex value'); From b0113addc1b8208ad5e11650aa36cfab9fb7a467 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 15:17:24 -0800 Subject: [PATCH 12/17] Fix hanging lint --- config/eslint/diagnostic.cjs | 3 +++ tests/ember-data__request/diagnostic.js | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/eslint/diagnostic.cjs b/config/eslint/diagnostic.cjs index 64e44246891..c5eb1e3d429 100644 --- a/config/eslint/diagnostic.cjs +++ b/config/eslint/diagnostic.cjs @@ -40,6 +40,9 @@ function config() { rules: { // It's ok to use unpublished files here since we don't ship these 'n/no-unpublished-require': 'off', + // TODO: '@warp-drive/diagnostic/server/default-setup.js' keeps setting these off + 'n/no-missing-import': 'off', + 'n/no-unpublished-import': 'off', }, }; } diff --git a/tests/ember-data__request/diagnostic.js b/tests/ember-data__request/diagnostic.js index 75db4662ade..b207883e528 100644 --- a/tests/ember-data__request/diagnostic.js +++ b/tests/ember-data__request/diagnostic.js @@ -1,5 +1,4 @@ /* global Bun */ -// eslint-disable-next-line n/no-missing-import, n/no-unpublished-import import launch from '@warp-drive/diagnostic/server/default-setup.js'; /** @type {import('bun-types')} */ From 86ec92068dadc5cfbbfec29352893549a8af1f1f Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Fri, 17 Nov 2023 15:37:07 -0800 Subject: [PATCH 13/17] Separate strict from loose-mode in tests/main eslintrc --- tests/main/.eslintrc.cjs | 21 ++++++++++ .../integration/identifiers/scenarios-test.ts | 42 +++++++++---------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/tests/main/.eslintrc.cjs b/tests/main/.eslintrc.cjs index d684313d796..fea89270c47 100644 --- a/tests/main/.eslintrc.cjs +++ b/tests/main/.eslintrc.cjs @@ -27,7 +27,28 @@ module.exports = { overrides: [ node.config(), node.defaults(), + typescript.defaults(), + // files converted to strict must pass these rules before they can be removed from + // the files list here + // see https://github.com/emberjs/data/issues/6233#issuecomment-849279594 typescript.defaults({ + files: [ + './tests/helpers/accessors.ts', + './tests/integration/identifiers/configuration-test.ts', + './tests/integration/identifiers/lid-reflection-test.ts', + './tests/integration/identifiers/new-records-test.ts', + './tests/integration/identifiers/polymorphic-scenarios-test.ts', + './tests/integration/identifiers/record-identifier-for-test.ts', + './tests/integration/identifiers/scenarios-test.ts', + './tests/integration/model-errors-test.ts', + './tests/integration/record-data/record-data-errors-test.ts', + './tests/integration/record-data/record-data-state-test.ts', + './tests/integration/record-data/record-data-test.ts', + './tests/integration/record-data/store-wrapper-test.ts', + './tests/integration/relationships/rollback-test.ts', + './tests/integration/request-state-service-test.ts', + './tests/unit/custom-class-support/custom-class-model-test.ts', + ], rules: { '@typescript-eslint/no-unsafe-assignment': 'off', '@typescript-eslint/no-unsafe-call': 'off', diff --git a/tests/main/tests/integration/identifiers/scenarios-test.ts b/tests/main/tests/integration/identifiers/scenarios-test.ts index 6a736aa9f96..7ac690d5a3a 100644 --- a/tests/main/tests/integration/identifiers/scenarios-test.ts +++ b/tests/main/tests/integration/identifiers/scenarios-test.ts @@ -1,4 +1,3 @@ - import EmberObject, { set } from '@ember/object'; import { module, test } from 'qunit'; @@ -16,12 +15,7 @@ import { setIdentifierUpdateMethod, } from '@ember-data/store'; import type { GenerationMethod, ResourceData } from '@ember-data/store/-types/q/identifier'; -import type { - Identifier, - IdentifierBucket, - StableIdentifier, - StableRecordIdentifier, -} from '@warp-drive/core-types/identifier'; +import type { IdentifierBucket, StableIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; function isNonEmptyString(str: unknown): str is string { return typeof str === 'string' && str.length > 0; @@ -35,17 +29,14 @@ module('Integration | Identifiers - scenarios', function (hooks) { setupTest(hooks); module('Secondary Cache based on an attribute', function (innerHooks) { - const calls = { - findRecord: 0, - queryRecord: 0, - }; + let calls; let isQuery = false; let secondaryCache: { id: { [key: string]: string }; username: { [key: string]: string }; }; class TestSerializer extends EmberObject { - normalizeResponse(_, __, payload: unknown) { + normalizeResponse(_, __, payload) { return payload; } } @@ -93,10 +84,15 @@ module('Integration | Identifiers - scenarios', function (hooks) { owner.register('serializer:application', TestSerializer); owner.register('model:user', User); + calls = { + findRecord: 0, + queryRecord: 0, + }; + let localIdInc = 9000; secondaryCache = { - id: Object.create(null) as Record, - username: Object.create(null) as Record, + id: Object.create(null), + username: Object.create(null), }; const generationMethod: GenerationMethod = (resource: unknown, bucket: IdentifierBucket) => { if (bucket !== 'record') { @@ -246,14 +242,11 @@ module('Integration | Identifiers - scenarios', function (hooks) { }); module('Secondary Cache using an attribute as an alternate id', function (innerHooks) { - const calls = { - findRecord: 0, - queryRecord: 0, - }; + let calls; let isQuery = false; let secondaryCache: { [key: string]: string }; class TestSerializer extends EmberObject { - normalizeResponse(_, __, payload: unknown) { + normalizeResponse(_, __, payload) { return payload; } } @@ -301,8 +294,13 @@ module('Integration | Identifiers - scenarios', function (hooks) { owner.register('serializer:application', TestSerializer); owner.register('model:user', User); + calls = { + findRecord: 0, + queryRecord: 0, + }; + let localIdInc = 9000; - secondaryCache = Object.create(null) as Record; + secondaryCache = Object.create(null); function lidForUser(resource: ResourceData | { type: string }): string { if ('type' in resource && resource.type === 'user') { @@ -661,7 +659,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { }); }; - function updateUsernameCache(identifier: Identifier, oldUsername: string, newUsername: string) { + function updateUsernameCache(identifier, oldUsername, newUsername) { if (secondaryCache[oldUsername] !== identifier.lid) { throw new Error(`Incorrect username update`); } @@ -670,7 +668,7 @@ module('Integration | Identifiers - scenarios', function (hooks) { } secondaryCache[newUsername] = identifier.lid; } - function commitUsernameUpdate(identifier: Identifier, oldUsername: string, newUsername: string) { + function commitUsernameUpdate(identifier, oldUsername, newUsername) { if (secondaryCache[oldUsername] === identifier.lid) { delete secondaryCache[oldUsername]; } From e95bbee6bdcf269127d824f9b6cf7fa534d91931 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Mon, 20 Nov 2023 14:22:19 -0800 Subject: [PATCH 14/17] Add eslintrc for tests/performance --- pnpm-lock.yaml | 3 ++ tests/performance/.eslintrc.cjs | 31 +++++++++++++++++++ .../routes/add-children-then-materialize.js | 2 +- .../relationship-materialization-complex.js | 2 +- tests/performance/config/environment.js | 2 +- tests/performance/ember-cli-build.js | 2 +- .../fixtures/create-parent-records.js | 8 ++--- tests/performance/package.json | 2 ++ 8 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 tests/performance/.eslintrc.cjs diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4434c31ab4c..26aedfaa390 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3953,6 +3953,9 @@ importers: '@glimmer/tracking': specifier: ^1.1.2 version: 1.1.2 + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-cli: specifier: ~5.4.0 version: 5.4.0 diff --git a/tests/performance/.eslintrc.cjs b/tests/performance/.eslintrc.cjs new file mode 100644 index 00000000000..1d0e93d70fb --- /dev/null +++ b/tests/performance/.eslintrc.cjs @@ -0,0 +1,31 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: ['@ember/application', '@ember/object', '@ember/routing/route', '@ember/service'], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults({ + files: ['./server/**/*.{js,ts}', './fixtures/**/*.{js,ts}'], + }), + ], +}; diff --git a/tests/performance/app/routes/add-children-then-materialize.js b/tests/performance/app/routes/add-children-then-materialize.js index 87267bb99bc..989ddaa7c5f 100644 --- a/tests/performance/app/routes/add-children-then-materialize.js +++ b/tests/performance/app/routes/add-children-then-materialize.js @@ -21,7 +21,7 @@ export default Route.extend({ this.store.peekAll('child').slice(); performance.mark('start-materialize-relationships'); - let seen = new Set(); + const seen = new Set(); peekedParents.forEach((parent) => iterateParent(parent, seen)); performance.mark('end-materialize-relationships'); diff --git a/tests/performance/app/routes/relationship-materialization-complex.js b/tests/performance/app/routes/relationship-materialization-complex.js index c9db131cdab..7892858bc43 100644 --- a/tests/performance/app/routes/relationship-materialization-complex.js +++ b/tests/performance/app/routes/relationship-materialization-complex.js @@ -16,7 +16,7 @@ export default Route.extend({ peekedChildren.slice(); peekedParents.slice(); performance.mark('start-relationship-materialization'); - let seen = new Set(); + const seen = new Set(); peekedParents.forEach((parent) => iterateParent(parent, seen)); performance.mark('end-relationship-materialization'); }, diff --git a/tests/performance/config/environment.js b/tests/performance/config/environment.js index 1e6942e6980..d5b7e8d3b9f 100644 --- a/tests/performance/config/environment.js +++ b/tests/performance/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'performance-test-app', environment, rootURL: '/', diff --git a/tests/performance/ember-cli-build.js b/tests/performance/ember-cli-build.js index 7b316bfcffc..691305f1420 100644 --- a/tests/performance/ember-cli-build.js +++ b/tests/performance/ember-cli-build.js @@ -5,7 +5,7 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { fingerprint: { enabled: false, }, diff --git a/tests/performance/fixtures/create-parent-records.js b/tests/performance/fixtures/create-parent-records.js index 52f912430f7..bc83f6de65c 100644 --- a/tests/performance/fixtures/create-parent-records.js +++ b/tests/performance/fixtures/create-parent-records.js @@ -12,7 +12,7 @@ module.exports = function createParentRecords(nrParents = 1, nrChildren, nrFrien }; for (let i = 0; i < nrParents; i++) { - let payload = createParentPayload(`${parentFixtureId++}`, nrChildren, nrFriends); + const payload = createParentPayload(`${parentFixtureId++}`, nrChildren, nrFriends); if (nrParents === 1) { return payload; @@ -55,7 +55,7 @@ function createParentPayload(parentId = '1', nrChildren = 0, nrFriends = 0) { const childIdentifier = extractIdentifiers(child); if (nrFriends > 0) { - let bestFriend = ALL_FRIENDS[friendIndex]; + const bestFriend = ALL_FRIENDS[friendIndex]; child.relationships.bestFriend = { data: extractIdentifiers(bestFriend), }; @@ -67,7 +67,7 @@ function createParentPayload(parentId = '1', nrChildren = 0, nrFriends = 0) { data: otherFriends, }; for (let i = 0; i < nrFriends; i++) { - let friend = ALL_FRIENDS[friendIndex + i]; + const friend = ALL_FRIENDS[friendIndex + i]; friend.relationships.friends = { data: [childIdentifier], }; @@ -75,7 +75,7 @@ function createParentPayload(parentId = '1', nrChildren = 0, nrFriends = 0) { } } if (nrFriends > 1) { - let secondBestFriend = ALL_FRIENDS[friendIndex + 1]; + const secondBestFriend = ALL_FRIENDS[friendIndex + 1]; child.relationships.secondBestFriend = { data: extractIdentifiers(secondBestFriend), }; diff --git a/tests/performance/package.json b/tests/performance/package.json index 963d0a22c19..f35f88597d5 100644 --- a/tests/performance/package.json +++ b/tests/performance/package.json @@ -17,6 +17,7 @@ "scripts": { "build": "ember build", "start": "ember serve", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", "_syncPnpm": "bun run sync-dependencies-meta-injected" }, "dependencies": { @@ -44,6 +45,7 @@ "@embroider/webpack": "^3.2.1", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", "ember-cli-dependency-checker": "^3.3.2", From 2b1219844ddbe0791abeee8cbb87beb1f29136a4 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Mon, 20 Nov 2023 14:37:56 -0800 Subject: [PATCH 15/17] Add tsconfig and eslintrc for tests/recommended-json-api --- pnpm-lock.yaml | 6 +++ tests/recommended-json-api/.eslintrc.cjs | 45 +++++++++++++++++++ tests/recommended-json-api/app/app.ts | 2 +- .../app/components/book-list.ts | 4 +- .../app/components/book-search.ts | 1 - .../app/components/infinite-books.ts | 1 - .../app/routes/application.ts | 6 +-- .../app/services/store.ts | 17 ++++--- .../app/utils/pagination-links.ts | 5 +-- .../config/environment.js | 2 +- tests/recommended-json-api/ember-cli-build.js | 4 +- tests/recommended-json-api/package.json | 4 ++ tests/recommended-json-api/server/index.js | 2 +- .../recommended-json-api/server/mocks/book.js | 14 +++--- tests/recommended-json-api/testem.js | 2 +- tests/recommended-json-api/tsconfig.json | 30 +++++++++++++ 16 files changed, 115 insertions(+), 30 deletions(-) create mode 100644 tests/recommended-json-api/.eslintrc.cjs create mode 100644 tests/recommended-json-api/tsconfig.json diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 26aedfaa390..3a28e92cb44 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4076,6 +4076,9 @@ importers: '@warp-drive/core-types': specifier: workspace:5.5.0-alpha.11 version: file:packages/core-types(@babel/core@7.23.3) + '@warp-drive/internal-config': + specifier: workspace:5.5.0-alpha.11 + version: link:../../config ember-auto-import: specifier: ^2.6.3 version: 2.6.3(webpack@5.89.0) @@ -4157,6 +4160,9 @@ importers: silent-error: specifier: ^1.1.1 version: 1.1.1 + typescript: + specifier: ^5.2.2 + version: 5.2.2 webpack: specifier: ^5.89.0 version: 5.89.0 diff --git a/tests/recommended-json-api/.eslintrc.cjs b/tests/recommended-json-api/.eslintrc.cjs new file mode 100644 index 00000000000..b9660bad7f1 --- /dev/null +++ b/tests/recommended-json-api/.eslintrc.cjs @@ -0,0 +1,45 @@ +const base = require('@warp-drive/internal-config/eslint/base.cjs'); +const ignore = require('@warp-drive/internal-config/eslint/ignore.cjs'); +const imports = require('@warp-drive/internal-config/eslint/imports.cjs'); +const isolation = require('@warp-drive/internal-config/eslint/isolation.cjs'); +const node = require('@warp-drive/internal-config/eslint/node.cjs'); +const parser = require('@warp-drive/internal-config/eslint/parser.cjs'); +const qunit = require('@warp-drive/internal-config/eslint/qunit.cjs'); +const typescript = require('@warp-drive/internal-config/eslint/typescript.cjs'); + +module.exports = { + ...parser.defaults(), + ...base.settings(), + + plugins: [...base.plugins(), ...imports.plugins()], + extends: [...base.extend()], + rules: Object.assign( + base.rules(), + imports.rules(), + isolation.rules({ + allowedImports: [ + '@ember/application', + '@ember/debug', + '@ember/routing/route', + '@ember/service', + '@glimmer/component', + '@glimmer/tracking', + ], + }), + {} + ), + + ignorePatterns: ignore.ignoreRules(), + + overrides: [ + node.config(), + node.defaults({ + files: ['./server/**/*.{js,ts}'], + }), + typescript.defaults(), + qunit.defaults({ + files: ['tests/**/*.{js,ts}'], + allowedImports: [], + }), + ], +}; diff --git a/tests/recommended-json-api/app/app.ts b/tests/recommended-json-api/app/app.ts index 1f39476ae86..8f235d166e6 100644 --- a/tests/recommended-json-api/app/app.ts +++ b/tests/recommended-json-api/app/app.ts @@ -8,7 +8,7 @@ import Resolver from './resolver'; class App extends Application { modulePrefix = config.modulePrefix; podModulePrefix = config.podModulePrefix; - Resolver = Resolver; + override Resolver = Resolver; } loadInitializers(App, config.modulePrefix); diff --git a/tests/recommended-json-api/app/components/book-list.ts b/tests/recommended-json-api/app/components/book-list.ts index 94aa2ee3021..f7baf01be72 100644 --- a/tests/recommended-json-api/app/components/book-list.ts +++ b/tests/recommended-json-api/app/components/book-list.ts @@ -1,6 +1,5 @@ import { service } from '@ember/service'; import Component from '@glimmer/component'; -// eslint-disable-next-line no-restricted-imports import { cached, tracked } from '@glimmer/tracking'; import { query } from '@ember-data/json-api/request'; @@ -9,7 +8,8 @@ import type Store from '@ember-data/store'; import type { Document } from '@ember-data/store/-private/document'; import type Book from '../models/book'; -import { ApiPage, PaginationLinks } from '../utils/pagination-links'; +import type { ApiPage} from '../utils/pagination-links'; +import { PaginationLinks } from '../utils/pagination-links'; export interface BookListSignature { Element: HTMLDivElement; diff --git a/tests/recommended-json-api/app/components/book-search.ts b/tests/recommended-json-api/app/components/book-search.ts index 30bdd53eb7c..8aab0aceac3 100644 --- a/tests/recommended-json-api/app/components/book-search.ts +++ b/tests/recommended-json-api/app/components/book-search.ts @@ -1,6 +1,5 @@ import { service } from '@ember/service'; import Component from '@glimmer/component'; -// eslint-disable-next-line no-restricted-imports import { cached, tracked } from '@glimmer/tracking'; import type Store from '@ember-data/store'; diff --git a/tests/recommended-json-api/app/components/infinite-books.ts b/tests/recommended-json-api/app/components/infinite-books.ts index a0dc764c0a5..07da7e93729 100644 --- a/tests/recommended-json-api/app/components/infinite-books.ts +++ b/tests/recommended-json-api/app/components/infinite-books.ts @@ -1,6 +1,5 @@ import { service } from '@ember/service'; import Component from '@glimmer/component'; -// eslint-disable-next-line no-restricted-imports import { tracked } from '@glimmer/tracking'; import type Store from '@ember-data/store'; diff --git a/tests/recommended-json-api/app/routes/application.ts b/tests/recommended-json-api/app/routes/application.ts index ade84276be4..8f630f67773 100644 --- a/tests/recommended-json-api/app/routes/application.ts +++ b/tests/recommended-json-api/app/routes/application.ts @@ -3,11 +3,11 @@ import { service } from '@ember/service'; import { query } from '@ember-data/json-api/request'; import { setBuildURLConfig } from '@ember-data/request-utils'; -import Store from '@ember-data/store'; +import type Store from '@ember-data/store'; import type { Document } from '@ember-data/store/-private/document'; import type Author from '../models/author'; -import Book from '../models/book'; +import type Book from '../models/book'; import type Genre from '../models/genre'; setBuildURLConfig({ @@ -18,7 +18,7 @@ setBuildURLConfig({ export default class ApplicationRoute extends Route { @service declare store: Store; - async model() { + override async model() { const genres = this.store.request>({ url: '/api/books/genres' }); const authors = this.store.request>({ url: '/api/books/authors' }); const books = this.store.request>(query('book')); diff --git a/tests/recommended-json-api/app/services/store.ts b/tests/recommended-json-api/app/services/store.ts index 86ac8e81210..274ae5a8fe5 100644 --- a/tests/recommended-json-api/app/services/store.ts +++ b/tests/recommended-json-api/app/services/store.ts @@ -1,5 +1,3 @@ -import type { StableRecordIdentifier } from '@warp-drive/core-types'; - import JSONAPICache from '@ember-data/json-api'; import type Model from '@ember-data/model'; import { instantiateRecord, teardownRecord } from '@ember-data/model'; @@ -8,8 +6,9 @@ import RequestManager from '@ember-data/request'; import Fetch from '@ember-data/request/fetch'; import { LifetimesService } from '@ember-data/request-utils'; import DataStore, { CacheHandler } from '@ember-data/store'; -import type { Cache } from '@ember-data/store/-types/cache/cache'; import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; +import type { StableRecordIdentifier } from '@warp-drive/core-types'; +import type { Cache } from '@warp-drive/core-types/cache'; import CONFIG from '../config/environment'; @@ -25,19 +24,23 @@ export default class Store extends DataStore { this.lifetimes = new LifetimesService(this, CONFIG); } - createCache(capabilities: CacheCapabilitiesManager): Cache { + override createCache(capabilities: CacheCapabilitiesManager): Cache { return new JSONAPICache(capabilities); } - instantiateRecord(identifier: StableRecordIdentifier, createRecordArgs: { [key: string]: unknown }): unknown { + override instantiateRecord( + identifier: StableRecordIdentifier, + createRecordArgs: { [key: string]: unknown } + ): unknown { return instantiateRecord.call(this, identifier, createRecordArgs); } - teardownRecord(record: Model): void { + override teardownRecord(record: Model): void { return teardownRecord.call(this, record); } - modelFor(type: string) { + // @ts-expect-error Not sure what the fix is here + override modelFor(type: string) { return modelFor.call(this, type); } } diff --git a/tests/recommended-json-api/app/utils/pagination-links.ts b/tests/recommended-json-api/app/utils/pagination-links.ts index 94fbb0b6d4a..db8f63a4df2 100644 --- a/tests/recommended-json-api/app/utils/pagination-links.ts +++ b/tests/recommended-json-api/app/utils/pagination-links.ts @@ -1,5 +1,4 @@ import { assert } from '@ember/debug'; -// eslint-disable-next-line no-restricted-imports import { tracked } from '@glimmer/tracking'; type ApiMeta = { @@ -33,7 +32,7 @@ export class PaginationLinks { const cached = _pages; _pages = this._pages = new Array(pagesTotal).fill('.') as string[]; for (let i = 0; i < pagesTotal; i++) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + _pages[i] = cached[i]!; } } @@ -64,7 +63,7 @@ export class PaginationLinks { filtered.push({ index: i + 1, link: pages[i] }); } else if ( filtered.length > 0 && - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + filtered[filtered.length - 1]!.link !== '...' ) { filtered.push({ index: i + 1, link: '...' }); diff --git a/tests/recommended-json-api/config/environment.js b/tests/recommended-json-api/config/environment.js index befd38360a8..3042a06465e 100644 --- a/tests/recommended-json-api/config/environment.js +++ b/tests/recommended-json-api/config/environment.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function (environment) { - let ENV = { + const ENV = { modulePrefix: 'recommended-json-api', environment, rootURL: '/', diff --git a/tests/recommended-json-api/ember-cli-build.js b/tests/recommended-json-api/ember-cli-build.js index fd2ea6503c6..5928eb9f215 100644 --- a/tests/recommended-json-api/ember-cli-build.js +++ b/tests/recommended-json-api/ember-cli-build.js @@ -1,10 +1,10 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function (defaults) { - let app = new EmberApp(defaults, { + const app = new EmberApp(defaults, { emberData: { compatWith: '99.0', }, diff --git a/tests/recommended-json-api/package.json b/tests/recommended-json-api/package.json index 05d437aef8f..e5c5ef1eee6 100644 --- a/tests/recommended-json-api/package.json +++ b/tests/recommended-json-api/package.json @@ -17,6 +17,8 @@ "scripts": { "build": "ember build", "start": "ember test --port=0 --serve --no-launch", + "lint": "eslint . --quiet --cache --cache-strategy=content --ext .js,.ts,.mjs,.cjs --report-unused-disable-directives", + "check:types": "tsc --noEmit", "test:examples": "ember test --test-port=0", "_syncPnpm": "bun run sync-dependencies-meta-injected" }, @@ -90,6 +92,7 @@ "@html-next/vertical-collection": "^4.0.2", "@types/morgan": "^1.9.9", "@warp-drive/core-types": "workspace:5.5.0-alpha.11", + "@warp-drive/internal-config": "workspace:5.5.0-alpha.11", "ember-auto-import": "^2.6.3", "ember-cli": "~5.4.0", "ember-cli-babel": "^8.2.0", @@ -117,6 +120,7 @@ "qunit-console-grouper": "^0.3.0", "qunit-dom": "^3.0.0", "silent-error": "^1.1.1", + "typescript": "^5.2.2", "webpack": "^5.89.0" }, "ember": { diff --git a/tests/recommended-json-api/server/index.js b/tests/recommended-json-api/server/index.js index 1d9786c7502..3a75c817fe0 100644 --- a/tests/recommended-json-api/server/index.js +++ b/tests/recommended-json-api/server/index.js @@ -1,4 +1,4 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; // To use it create some files under `mocks/` diff --git a/tests/recommended-json-api/server/mocks/book.js b/tests/recommended-json-api/server/mocks/book.js index 6535bfcb0e8..5fbd161845f 100644 --- a/tests/recommended-json-api/server/mocks/book.js +++ b/tests/recommended-json-api/server/mocks/book.js @@ -1,4 +1,4 @@ -/* eslint-disable n/no-unpublished-require */ + 'use strict'; const RAW_BOOKS = require('./MOCK_DATA.json'); @@ -42,14 +42,14 @@ const CATEGORIES = RAW_BOOKS.reduce((acc, book) => { }); function getPage(books, page = 1, limit = DEFAULT_LIMIT) { - let start = (page - 1) * limit; - let end = page * limit; + const start = (page - 1) * limit; + const end = page * limit; return books.slice(start, end); } function buildLink(page = 1, limit = DEFAULT_LIMIT, filter, sort, author, genre) { - let url = '/api/books'; - let params = []; + const url = '/api/books'; + const params = []; if (author) { params.push(`author=${author}`); } @@ -94,7 +94,7 @@ function getLinks(books, page, limit, filter, sort, author, genre) { module.exports = function (app) { const express = require('express'); - let bookRouter = express.Router(); + const bookRouter = express.Router(); app.set('json spaces', 0); app.set('env', 'production'); @@ -130,7 +130,7 @@ module.exports = function (app) { const fields = sort.split(',').map((field) => field.split(':')); books.sort((a, b) => { - for (let [field, order] of fields) { + for (const [field, order] of fields) { const valA = field === 'publicationDate' ? new Date(a.attributes[field]).getTime() : a.attributes[field]; const valB = field === 'publicationDate' ? new Date(b.attributes[field]).getTime() : b.attributes[field]; if (valA === valB) { diff --git a/tests/recommended-json-api/testem.js b/tests/recommended-json-api/testem.js index 914019b375e..5b07693c97c 100644 --- a/tests/recommended-json-api/testem.js +++ b/tests/recommended-json-api/testem.js @@ -1,4 +1,4 @@ -/* eslint-disable n/no-unpublished-require */ + const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console diff --git a/tests/recommended-json-api/tsconfig.json b/tests/recommended-json-api/tsconfig.json new file mode 100644 index 00000000000..3a781c7337e --- /dev/null +++ b/tests/recommended-json-api/tsconfig.json @@ -0,0 +1,30 @@ +{ + "include": ["app/**/*", "config/**/*", "tests/**/*"], + "baseUrl": ".", + "compilerOptions": { + "lib": ["DOM", "ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "strict": true, + "downlevelIteration": true, + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + + "noImplicitOverride": true, + + "experimentalDecorators": true, + + "incremental": true, + + "noEmit": true, + "declaration": false, + + "types": ["ember-source/types"], + "paths": {} + }, + "references": [] +} From 8b489f52b5a6a44bd7ad537dd94c0c2ba295d7cf Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Mon, 20 Nov 2023 14:42:17 -0800 Subject: [PATCH 16/17] Run lint:prettier:fix --- tests/builders/ember-cli-build.js | 1 - tests/ember-data__graph/ember-cli-build.js | 1 - tests/ember-data__json-api/ember-cli-build.js | 1 - .../cache/resource-data-documents-test.ts | 6 +++++- tests/ember-data__request/ember-cli-build.js | 1 - .../tests/integration/graceful-dev-errors-test.ts | 4 ---- .../integration/graceful-dev-handler-errors-test.ts | 4 ---- tests/ember-data__serializer/testem.js | 1 - tests/embroider-basic-compat/testem.js | 1 - tests/fastboot/testem.js | 1 - tests/main/config/ember-try.js | 1 - tests/main/ember-cli-build.js | 1 - tests/main/testem.js | 1 - .../cache-handler/store-package-setup-test.ts | 6 +++++- .../identifiers/record-identifier-for-test.ts | 1 - tests/main/tests/integration/model-errors-test.ts | 1 - .../record-data/record-data-errors-test.ts | 12 +++++------- .../record-data/record-data-state-test.ts | 5 ++--- .../integration/record-data/record-data-test.ts | 1 - .../integration/record-data/store-wrapper-test.ts | 1 - .../tests/integration/relationships/rollback-test.ts | 8 ++++---- .../tests/integration/request-state-service-test.ts | 3 +-- .../tests/unit/utils/parse-response-headers-test.js | 8 +++++--- .../recommended-json-api/app/components/book-list.ts | 2 +- .../app/utils/pagination-links.ts | 7 +------ tests/recommended-json-api/ember-cli-build.js | 1 - tests/recommended-json-api/server/index.js | 1 - tests/recommended-json-api/server/mocks/book.js | 1 - tests/recommended-json-api/testem.js | 1 - 29 files changed, 29 insertions(+), 54 deletions(-) diff --git a/tests/builders/ember-cli-build.js b/tests/builders/ember-cli-build.js index 6a145f21adb..35799698982 100644 --- a/tests/builders/ember-cli-build.js +++ b/tests/builders/ember-cli-build.js @@ -1,4 +1,3 @@ - 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); diff --git a/tests/ember-data__graph/ember-cli-build.js b/tests/ember-data__graph/ember-cli-build.js index bd540a4814b..90beb108c7d 100644 --- a/tests/ember-data__graph/ember-cli-build.js +++ b/tests/ember-data__graph/ember-cli-build.js @@ -1,4 +1,3 @@ - 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); diff --git a/tests/ember-data__json-api/ember-cli-build.js b/tests/ember-data__json-api/ember-cli-build.js index 4a1ecce4129..effea243257 100644 --- a/tests/ember-data__json-api/ember-cli-build.js +++ b/tests/ember-data__json-api/ember-cli-build.js @@ -1,4 +1,3 @@ - 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); diff --git a/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts b/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts index 422d30ba85a..a5b2be2545d 100644 --- a/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts +++ b/tests/ember-data__json-api/tests/integration/cache/resource-data-documents-test.ts @@ -6,7 +6,11 @@ import type { CacheOperation, NotificationType } from '@ember-data/store/-privat import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache-store-wrapper'; import type { JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; -import type { StableDocumentIdentifier,StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; +import type { + StableDocumentIdentifier, + StableExistingRecordIdentifier, + StableRecordIdentifier, +} from '@warp-drive/core-types/identifier'; import type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema'; import type { SingleResourceDataDocument } from '@warp-drive/core-types/spec/document'; import type { SingleResourceDocument } from '@warp-drive/core-types/spec/raw'; diff --git a/tests/ember-data__request/ember-cli-build.js b/tests/ember-data__request/ember-cli-build.js index 6a145f21adb..35799698982 100644 --- a/tests/ember-data__request/ember-cli-build.js +++ b/tests/ember-data__request/ember-cli-build.js @@ -1,4 +1,3 @@ - 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); diff --git a/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts b/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts index dda974854c0..f228bde093a 100644 --- a/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts +++ b/tests/ember-data__request/tests/integration/graceful-dev-errors-test.ts @@ -1,7 +1,3 @@ - - - - import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Handler, NextFn } from '@ember-data/request/-private/types'; diff --git a/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts b/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts index f5891dac324..bc5a52c1eea 100644 --- a/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts +++ b/tests/ember-data__request/tests/integration/graceful-dev-handler-errors-test.ts @@ -1,7 +1,3 @@ - - - - import RequestManager from '@ember-data/request'; import type { Context } from '@ember-data/request/-private/context'; import type { Handler, NextFn } from '@ember-data/request/-private/types'; diff --git a/tests/ember-data__serializer/testem.js b/tests/ember-data__serializer/testem.js index 2d19b92e408..a9df5e60abb 100644 --- a/tests/ember-data__serializer/testem.js +++ b/tests/ember-data__serializer/testem.js @@ -1,4 +1,3 @@ - const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console diff --git a/tests/embroider-basic-compat/testem.js b/tests/embroider-basic-compat/testem.js index 2d19b92e408..a9df5e60abb 100644 --- a/tests/embroider-basic-compat/testem.js +++ b/tests/embroider-basic-compat/testem.js @@ -1,4 +1,3 @@ - const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console diff --git a/tests/fastboot/testem.js b/tests/fastboot/testem.js index 2d19b92e408..a9df5e60abb 100644 --- a/tests/fastboot/testem.js +++ b/tests/fastboot/testem.js @@ -1,4 +1,3 @@ - const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console diff --git a/tests/main/config/ember-try.js b/tests/main/config/ember-try.js index dec1e9fcf68..b5b96aa1674 100644 --- a/tests/main/config/ember-try.js +++ b/tests/main/config/ember-try.js @@ -1,4 +1,3 @@ - 'use strict'; const getChannelURL = require('ember-source-channel-url'); diff --git a/tests/main/ember-cli-build.js b/tests/main/ember-cli-build.js index 610d5ed2e7e..9ed5cbb3b40 100644 --- a/tests/main/ember-cli-build.js +++ b/tests/main/ember-cli-build.js @@ -1,4 +1,3 @@ - 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); diff --git a/tests/main/testem.js b/tests/main/testem.js index 41a3edfa5b9..b65e2597d27 100644 --- a/tests/main/testem.js +++ b/tests/main/testem.js @@ -1,4 +1,3 @@ - const TestemConfig = require('@ember-data/unpublished-test-infra/src/testem/testem'); module.exports = TestemConfig; diff --git a/tests/main/tests/integration/cache-handler/store-package-setup-test.ts b/tests/main/tests/integration/cache-handler/store-package-setup-test.ts index ca8da5761df..46f0d5ad10b 100644 --- a/tests/main/tests/integration/cache-handler/store-package-setup-test.ts +++ b/tests/main/tests/integration/cache-handler/store-package-setup-test.ts @@ -19,7 +19,11 @@ import type { CacheCapabilitiesManager } from '@ember-data/store/-types/q/cache- import type { JsonApiResource } from '@ember-data/store/-types/q/record-data-json-api'; import type { RecordInstance } from '@ember-data/store/-types/q/record-instance'; import type { FieldSchema } from '@ember-data/store/-types/q/schema-service'; -import type { StableDocumentIdentifier,StableExistingRecordIdentifier, StableRecordIdentifier } from '@warp-drive/core-types/identifier'; +import type { + StableDocumentIdentifier, + StableExistingRecordIdentifier, + StableRecordIdentifier, +} from '@warp-drive/core-types/identifier'; import type { CollectionResourceDataDocument, ResourceDataDocument, diff --git a/tests/main/tests/integration/identifiers/record-identifier-for-test.ts b/tests/main/tests/integration/identifiers/record-identifier-for-test.ts index 8dafcecb4d0..f52e5641e6e 100644 --- a/tests/main/tests/integration/identifiers/record-identifier-for-test.ts +++ b/tests/main/tests/integration/identifiers/record-identifier-for-test.ts @@ -10,7 +10,6 @@ import type Store from '@ember-data/store'; import { recordIdentifierFor } from '@ember-data/store'; class User extends Model { - @attr() name; } diff --git a/tests/main/tests/integration/model-errors-test.ts b/tests/main/tests/integration/model-errors-test.ts index eb2f1c2032b..435f9de530c 100644 --- a/tests/main/tests/integration/model-errors-test.ts +++ b/tests/main/tests/integration/model-errors-test.ts @@ -1,4 +1,3 @@ - import 'qunit-dom'; // tell TS consider *.dom extension for assert import { setComponentTemplate } from '@ember/component'; diff --git a/tests/main/tests/integration/record-data/record-data-errors-test.ts b/tests/main/tests/integration/record-data/record-data-errors-test.ts index 2216c3211dd..76268a90c06 100644 --- a/tests/main/tests/integration/record-data/record-data-errors-test.ts +++ b/tests/main/tests/integration/record-data/record-data-errors-test.ts @@ -340,7 +340,7 @@ module('integration/record-data Custom RecordData (v2) Errors', function (hooks) }) as Model; const identifier = recordIdentifierFor(person); - + let nameError = person.errors.errorsFor('firstName').objectAt(0); assert.strictEqual(nameError, undefined, 'no error shows up on firstName initially'); assert.true(person.isValid, 'person is initially valid'); @@ -356,16 +356,14 @@ module('integration/record-data Custom RecordData (v2) Errors', function (hooks) ]; storeWrapper.notifyChange(identifier, 'errors'); - nameError = person.errors.errorsFor('firstName').objectAt(0); - + assert.strictEqual(nameError?.attribute, 'firstName', 'error shows up on name'); assert.false(person.isValid, 'person is not valid'); errorsToReturn = []; storeWrapper.notifyChange(identifier, 'errors'); - assert.strictEqual(person.errors.errorsFor('firstName').length, 0, 'no errors on name'); assert.true(person.isValid, 'person is valid'); @@ -381,11 +379,11 @@ module('integration/record-data Custom RecordData (v2) Errors', function (hooks) storeWrapper.notifyChange(identifier, 'errors'); assert.false(person.isValid, 'person is not valid'); - + assert.strictEqual(person.errors.errorsFor('firstName').length, 0, 'no errors on firstName'); - + const lastNameError = person.errors.errorsFor('lastName').objectAt(0); - + assert.strictEqual(lastNameError?.attribute, 'lastName', 'error shows up on lastName'); }); }); diff --git a/tests/main/tests/integration/record-data/record-data-state-test.ts b/tests/main/tests/integration/record-data/record-data-state-test.ts index 7814c7c3bf0..c265e20a1c8 100644 --- a/tests/main/tests/integration/record-data/record-data-state-test.ts +++ b/tests/main/tests/integration/record-data/record-data-state-test.ts @@ -38,11 +38,10 @@ import type { class Person extends Model { // TODO fix the typing for naked attrs - + @attr('string', {}) name; - @attr('string', {}) lastName; } @@ -220,7 +219,7 @@ module('integration/record-data - Record Data State', function (hooks) { owner.register('model:person', Person); // @ts-expect-error missing type - + owner.unregister('service:store'); owner.register('service:store', Store); owner.register('serializer:application', JSONAPISerializer); diff --git a/tests/main/tests/integration/record-data/record-data-test.ts b/tests/main/tests/integration/record-data/record-data-test.ts index 65e6d783eff..11d8f1da3b6 100644 --- a/tests/main/tests/integration/record-data/record-data-test.ts +++ b/tests/main/tests/integration/record-data/record-data-test.ts @@ -1,4 +1,3 @@ - import EmberObject from '@ember/object'; import { settled } from '@ember/test-helpers'; diff --git a/tests/main/tests/integration/record-data/store-wrapper-test.ts b/tests/main/tests/integration/record-data/store-wrapper-test.ts index 84b6b210386..5e3d9ae124f 100644 --- a/tests/main/tests/integration/record-data/store-wrapper-test.ts +++ b/tests/main/tests/integration/record-data/store-wrapper-test.ts @@ -1,4 +1,3 @@ - import { settled } from '@ember/test-helpers'; import { module, test } from 'qunit'; diff --git a/tests/main/tests/integration/relationships/rollback-test.ts b/tests/main/tests/integration/relationships/rollback-test.ts index 8f3c48750fd..56789262f25 100644 --- a/tests/main/tests/integration/relationships/rollback-test.ts +++ b/tests/main/tests/integration/relationships/rollback-test.ts @@ -8,21 +8,21 @@ import type { StableRecordIdentifier } from '@warp-drive/core-types'; class App extends Model { @attr declare name: string; - + @hasMany('config', { async: false, inverse: 'app' }) declare configs: Config[]; - + @belongsTo('cluster', { async: false, inverse: 'apps' }) declare cluster: Cluster; } class Cluster extends Model { @attr declare name: string; - + @hasMany('app', { async: false, inverse: 'cluster' }) declare apps: App[]; } class Config extends Model { @attr declare name: string; - + @belongsTo('app', { async: false, inverse: 'configs' }) declare app: App | null; } diff --git a/tests/main/tests/integration/request-state-service-test.ts b/tests/main/tests/integration/request-state-service-test.ts index 447ef71b4ba..56089471517 100644 --- a/tests/main/tests/integration/request-state-service-test.ts +++ b/tests/main/tests/integration/request-state-service-test.ts @@ -10,11 +10,10 @@ import type Store from '@ember-data/store'; class Person extends Model { // TODO fix the typing for naked attrs - + @attr('string', {}) name; - @attr('string', {}) lastName; } diff --git a/tests/main/tests/unit/utils/parse-response-headers-test.js b/tests/main/tests/unit/utils/parse-response-headers-test.js index d31d82b8abf..5b1ecadfe50 100644 --- a/tests/main/tests/unit/utils/parse-response-headers-test.js +++ b/tests/main/tests/unit/utils/parse-response-headers-test.js @@ -82,9 +82,11 @@ module('unit/adapters/parse-response-headers', function () { ('\r\nfoo: bar'); test('ignores headers that do not contain a colon', function (assert) { - const headersString = ['Content-Encoding: gzip', 'I am ignored because I do not contain a colon', 'apple: pie'].join( - CRLF - ); + const headersString = [ + 'Content-Encoding: gzip', + 'I am ignored because I do not contain a colon', + 'apple: pie', + ].join(CRLF); const headers = parseResponseHeaders(headersString); diff --git a/tests/recommended-json-api/app/components/book-list.ts b/tests/recommended-json-api/app/components/book-list.ts index f7baf01be72..8bdce10bfde 100644 --- a/tests/recommended-json-api/app/components/book-list.ts +++ b/tests/recommended-json-api/app/components/book-list.ts @@ -8,7 +8,7 @@ import type Store from '@ember-data/store'; import type { Document } from '@ember-data/store/-private/document'; import type Book from '../models/book'; -import type { ApiPage} from '../utils/pagination-links'; +import type { ApiPage } from '../utils/pagination-links'; import { PaginationLinks } from '../utils/pagination-links'; export interface BookListSignature { diff --git a/tests/recommended-json-api/app/utils/pagination-links.ts b/tests/recommended-json-api/app/utils/pagination-links.ts index db8f63a4df2..419db283fb2 100644 --- a/tests/recommended-json-api/app/utils/pagination-links.ts +++ b/tests/recommended-json-api/app/utils/pagination-links.ts @@ -32,7 +32,6 @@ export class PaginationLinks { const cached = _pages; _pages = this._pages = new Array(pagesTotal).fill('.') as string[]; for (let i = 0; i < pagesTotal; i++) { - _pages[i] = cached[i]!; } } @@ -61,11 +60,7 @@ export class PaginationLinks { for (let i = 0; i < pages.length; i++) { if (pages[i] !== '.') { filtered.push({ index: i + 1, link: pages[i] }); - } else if ( - filtered.length > 0 && - - filtered[filtered.length - 1]!.link !== '...' - ) { + } else if (filtered.length > 0 && filtered[filtered.length - 1]!.link !== '...') { filtered.push({ index: i + 1, link: '...' }); } } diff --git a/tests/recommended-json-api/ember-cli-build.js b/tests/recommended-json-api/ember-cli-build.js index 5928eb9f215..e6790e9743c 100644 --- a/tests/recommended-json-api/ember-cli-build.js +++ b/tests/recommended-json-api/ember-cli-build.js @@ -1,4 +1,3 @@ - 'use strict'; const EmberApp = require('ember-cli/lib/broccoli/ember-app'); diff --git a/tests/recommended-json-api/server/index.js b/tests/recommended-json-api/server/index.js index 3a75c817fe0..f28263c054f 100644 --- a/tests/recommended-json-api/server/index.js +++ b/tests/recommended-json-api/server/index.js @@ -1,4 +1,3 @@ - 'use strict'; // To use it create some files under `mocks/` diff --git a/tests/recommended-json-api/server/mocks/book.js b/tests/recommended-json-api/server/mocks/book.js index 5fbd161845f..bf0b7cfbae0 100644 --- a/tests/recommended-json-api/server/mocks/book.js +++ b/tests/recommended-json-api/server/mocks/book.js @@ -1,4 +1,3 @@ - 'use strict'; const RAW_BOOKS = require('./MOCK_DATA.json'); diff --git a/tests/recommended-json-api/testem.js b/tests/recommended-json-api/testem.js index 5b07693c97c..491eb29ca44 100644 --- a/tests/recommended-json-api/testem.js +++ b/tests/recommended-json-api/testem.js @@ -1,4 +1,3 @@ - const customDotReporter = require('@ember-data/unpublished-test-infra/src/testem/custom-dot-reporter'); // eslint-disable-next-line no-console From caf0ad806dbe81aeb714784253522dd6bf288ef2 Mon Sep 17 00:00:00 2001 From: Krystan HuffMenne Date: Mon, 20 Nov 2023 14:43:19 -0800 Subject: [PATCH 17/17] Fix typo --- .vscode/settings.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 29de30d61be..3d96a190806 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,5 @@ "turbo.json": "jsonc" }, "eslint.workingDirectories": [{ "mode": "auto" }, "packages/*", "tests/*"], - "editor.formatOnSave": true, - "cSpell.words": ["Moomin"] + "editor.formatOnSave": true }