diff --git a/addons/api/addon/initializers/deprecations.js b/addons/api/addon/initializers/deprecations.js new file mode 100644 index 000000000..37ff8a47b --- /dev/null +++ b/addons/api/addon/initializers/deprecations.js @@ -0,0 +1,27 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { registerDeprecationHandler } from '@ember/debug'; + +const deprecationList = ['ember-data:deprecate-early-static']; + +export function initialize() { + registerDeprecationHandler((message, options, next) => { + // TODO: Remove deprecation handling for `deprecate-early-static` warning + // once we upgrade to ember-cli-mirage v3.0.0 which fixes this issue. + // More info about this issue here: https://github.com/miragejs/ember-cli-mirage/issues/2441 + if (options?.id && deprecationList.includes(options.id)) { + return; + } + if (options?.url) { + message += options.url; + } + next(message, options); + }); +} + +export default { + initialize, +}; diff --git a/addons/api/app/initializers/deprecations.js b/addons/api/app/initializers/deprecations.js new file mode 100644 index 000000000..577cfdd3d --- /dev/null +++ b/addons/api/app/initializers/deprecations.js @@ -0,0 +1 @@ +export { default, initialize } from 'api/initializers/deprecations'; diff --git a/addons/api/tests/unit/initializers/deprecations-test.js b/addons/api/tests/unit/initializers/deprecations-test.js new file mode 100644 index 000000000..79f0ae071 --- /dev/null +++ b/addons/api/tests/unit/initializers/deprecations-test.js @@ -0,0 +1,37 @@ +import Application from '@ember/application'; + +import config from 'dummy/config/environment'; +import { initialize } from 'dummy/initializers/deprecations'; +import { module, test } from 'qunit'; +import Resolver from 'ember-resolver'; +import { run } from '@ember/runloop'; + +module('Unit | Initializer | deprecations', function (hooks) { + hooks.beforeEach(function () { + this.TestApplication = class TestApplication extends Application { + modulePrefix = config.modulePrefix; + podModulePrefix = config.podModulePrefix; + Resolver = Resolver; + }; + + this.TestApplication.initializer({ + name: 'initializer under test', + initialize, + }); + + this.application = this.TestApplication.create({ + autoboot: false, + }); + }); + + hooks.afterEach(function () { + run(this.application, 'destroy'); + }); + + // TODO: Replace this with your real tests. + test('it works', async function (assert) { + await this.application.boot(); + + assert.ok(true); + }); +}); diff --git a/addons/api/tests/unit/utils/indexed-db-query-test.js b/addons/api/tests/unit/utils/indexed-db-query-test.js index e40e438a7..1720ee10a 100644 --- a/addons/api/tests/unit/utils/indexed-db-query-test.js +++ b/addons/api/tests/unit/utils/indexed-db-query-test.js @@ -4,10 +4,12 @@ import { setupTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import { setupIndexedDb } from 'api/test-support/helpers/indexed-db'; import { pluralize } from 'ember-inflector'; +import { camelize } from '@ember/string'; import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target'; const seedIndexDb = async (resource, store, indexedDb, server) => { - const resourceData = server.schema[pluralize(resource)].all().models; + const resourceData = + server.schema[pluralize(camelize(resource))].all().models; const serializedData = resourceData.map((resource) => JSON.parse(JSON.stringify(server.serializerOrRegistry.serialize(resource))), ); @@ -494,4 +496,32 @@ module('Unit | Utility | indexed-db-query', function (hooks) { assert.strictEqual(result.length, 1); }); + + test('it filters on boolean type fields with truthy value', async function (assert) { + const authMethod = this.server.create('auth-method', { + name: 'Generated_auth_method', + scopeId: scope1.id, + }); + scope1.update({ primaryAuthMethodId: authMethod.id }); + await seedIndexDb('auth-method', store, indexedDb, this.server); + const query = { filters: { is_primary: [{ equals: 'true' }] } }; + + const result = await queryIndexedDb(indexedDb.db, 'auth-method', query); + + assert.strictEqual(result.length, 1); + }); + + test('it filters on boolean type fields with falsy value', async function (assert) { + const authMethod = this.server.create('auth-method', { + name: 'Generated_auth_method', + scopeId: scope1.id, + }); + scope1.update({ primaryAuthMethodId: authMethod.id }); + await seedIndexDb('auth-method', store, indexedDb, this.server); + const query = { filters: { is_primary: [{ equals: 'false' }] } }; + + const result = await queryIndexedDb(indexedDb.db, 'auth-method', query); + + assert.strictEqual(result.length, 0); + }); });