Icu 13218 update indexed db parser unit tests to test for filtering on boolean fields (#2238)
* test: 💍 unit tests for bool fields * chore: 🤖 add deprecation handling ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13218
This commit is contained in:
1 parent
5e7c25a1fa
commit
c550faddb4
4 files changed
+96
-1
No files matched your search
@@ -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,
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { default, initialize } from 'api/initializers/deprecations';
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user