Skip to content

Commit

Permalink
convert builders tests
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Oct 17, 2023
1 parent 3cf3006 commit 5f78d66
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 151 deletions.
3 changes: 3 additions & 0 deletions packages/model/src/-private/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class Model extends EmberObject {
rollbackAttributes(): void;
changedAttributes(): Record<string, [unknown, unknown]>;
[key: string]: unknown;
isSaving: boolean;
isNew: boolean;
isDeleted: boolean;
hasDirtyAttributes: boolean;
deleteRecord(): void;
unloadRecord(): void;
serialize(): Record<string, unknown>;
Expand Down
17 changes: 5 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/builders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Provides testing for the Request and URL Building Utils

- @ember-data/active-record/request
- @ember-data/json-api/request
- @ember-data/rest/request
- @ember-data/request-utils
3 changes: 3 additions & 0 deletions tests/builders/diagnostic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import launch from '@warp-drive/diagnostic/server/default-setup.js';

await launch();
4 changes: 1 addition & 3 deletions tests/builders/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function (defaults) {
emberData: {
compatWith,
},
tests: true,
babel: {
// this ensures that the same build-time code stripping that is done
// for library packages is also done for our tests and dummy app
Expand All @@ -26,9 +27,6 @@ module.exports = function (defaults) {
throwUnlessParallelizable: true,
enableTypeScriptTransform: true,
},
'ember-cli-terser': {
exclude: ['assets/dummy.js', 'assets/tests.js', 'assets/test-support.js'],
},
});

/*
Expand Down
14 changes: 7 additions & 7 deletions tests/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"test": "tests"
},
"scripts": {
"build": "ember build",
"start": "ember test --port=0 --serve --no-launch",
"test": "ember test --test-port=0"
"build": "ember build --output-path=dist-test --suppress-sizes",
"test": "pnpm build && bun ./diagnostic.js",
"test:production": "pnpm build -e production; bun ./diagnostic.js"
},
"dependenciesMeta": {
"@ember-data/json-api": {
Expand Down Expand Up @@ -48,6 +48,9 @@
},
"@ember-data/unpublished-test-infra": {
"injected": true
},
"@warp-drive/diagnostic": {
"injected": true
}
},
"devDependencies": {
Expand All @@ -72,6 +75,7 @@
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@types/ember__owner": "^4.0.6",
"@warp-drive/diagnostic": "workspace:5.5.0-alpha.11",
"ember-auto-import": "^2.6.3",
"ember-cli": "~5.3.0",
"ember-cli-babel": "^8.2.0",
Expand All @@ -83,14 +87,10 @@
"ember-inflector": "^4.0.2",
"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^1.0.0",
"ember-qunit": "^8.0.1",
"ember-resolver": "^11.0.1",
"ember-source": "~5.3.0",
"ember-source-channel-url": "^3.0.0",
"loader.js": "^4.7.0",
"qunit": "^2.20.0",
"qunit-console-grouper": "^0.3.0",
"qunit-dom": "^3.0.0",
"silent-error": "^1.1.1",
"webpack": "^5.88.2"
},
Expand Down
30 changes: 0 additions & 30 deletions tests/builders/testem.js

This file was deleted.

12 changes: 3 additions & 9 deletions tests/builders/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Request Builders Tests</title>
<title>Request Builder Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

Expand All @@ -12,7 +12,6 @@

<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/builders-test-app.css">
<link rel="stylesheet" href="{{rootURL}}assets/test-support.css">

{{content-for "head-footer"}}
{{content-for "test-head-footer"}}
Expand All @@ -21,14 +20,9 @@
{{content-for "body"}}
{{content-for "test-body"}}

<div id="qunit"></div>
<div id="qunit-fixture">
<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
</div>
<div id="warp-drive__diagnostic"></div>
<div id="warp-drive__diagnostic-fixture"></div>

<script src="/testem.js" integrity=""></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
<script src="{{rootURL}}assets/builders-test-app.js"></script>
Expand Down
18 changes: 9 additions & 9 deletions tests/builders/tests/integration/create-record-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { module, test } from '@warp-drive/diagnostic';

import { setupTest } from 'ember-qunit';
import { setupTest } from '@ember-data/unpublished-test-infra/test-support/test-helpers';

import JSONAPICache from '@ember-data/json-api';
import { createRecord } from '@ember-data/json-api/request';
Expand Down Expand Up @@ -131,8 +131,8 @@ module('Integration - createRecord', function (hooks) {

await promise;

assert.strictEqual(user.id, '1', 'The user is updated from the response');
assert.strictEqual(user.name, 'Chris', 'The user is updated from the response');
assert.equal(user.id, '1', 'The user is updated from the response');
assert.equal(user.name, 'Chris', 'The user is updated from the response');
assert.false(user.hasDirtyAttributes, 'The user is no longer dirty');
assert.false(user.isNew, 'The user is no longer new');
assert.false(user.isSaving, 'The user is no longer saving');
Expand Down Expand Up @@ -223,15 +223,15 @@ module('Integration - createRecord', function (hooks) {
assert.ok(false, 'The promise should reject');
} catch (e: unknown) {
assert.true(e instanceof Error, 'The error is an error');
assert.strictEqual((e as Error).message, 'Something went wrong', 'The error has the expected error message');
assert.equal((e as Error).message, 'Something went wrong', 'The error has the expected error message');
assert.true(
Array.isArray((e as { content: { errors: JsonApiError[] } })?.content?.errors),
'The error has an errors array'
);
}

assert.strictEqual(user.id, null, 'The user is not updated from the response');
assert.strictEqual(user.name, 'John', 'The user is not updated from the response');
assert.equal(user.id, null, 'The user is not updated from the response');
assert.equal(user.name, 'John', 'The user is not updated from the response');
assert.true(user.hasDirtyAttributes, 'The user is still dirty');
assert.true(user.isNew, 'The user is still new');
assert.false(user.isDeleted, 'The user is not deleted');
Expand All @@ -244,8 +244,8 @@ module('Integration - createRecord', function (hooks) {
message: string;
}>;

assert.strictEqual(nameErrors.length, 1, 'The user has the expected number of errors');
assert.strictEqual(
assert.equal(nameErrors.length, 1, 'The user has the expected number of errors');
assert.equal(
nameErrors[0]?.message,
'Name must be capitalized',
'The user has the expected error for the field'
Expand Down
28 changes: 14 additions & 14 deletions tests/builders/tests/integration/delete-record-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { module, test } from '@warp-drive/diagnostic';

import { setupTest } from 'ember-qunit';
import { setupTest } from '@ember-data/unpublished-test-infra/test-support/test-helpers';

import JSONAPICache from '@ember-data/json-api';
import { deleteRecord } from '@ember-data/json-api/request';
Expand Down Expand Up @@ -135,25 +135,25 @@ module('Integration - deleteRecord', function (hooks) {
assert.true(user.isDeleted, 'The user is deleted');
assert.false(user.isSaving, 'The user is not saving');
assert.true(user.hasDirtyAttributes, 'The user is dirty');
assert.strictEqual(user.currentState.stateName, 'root.deleted.uncommitted', 'The user is in the correct state');
assert.strictEqual(user.dirtyType, 'deleted', 'The user is dirty with the correct type');
assert.equal(user.currentState.stateName, 'root.deleted.uncommitted', 'The user is in the correct state');
assert.equal(user.dirtyType, 'deleted', 'The user is dirty with the correct type');

const promise = store.request(deleteRecord(user));
assert.true(user.isSaving, 'The user is saving');

await promise;

assert.false(user.hasDirtyAttributes, 'The user is not dirty');
assert.strictEqual(user.currentState.stateName, 'root.deleted.saved', 'The user is in the correct state');
assert.strictEqual(user.dirtyType, '', 'The user is no longer dirty');
assert.equal(user.currentState.stateName, 'root.deleted.saved', 'The user is in the correct state');
assert.equal(user.dirtyType, '', 'The user is no longer dirty');
assert.true(user.isDeleted, 'The user is deleted');
assert.false(user.isSaving, 'The user is no longer saving');

assert.verifySteps([`willCommit ${identifier.lid}`, 'handle deleteRecord request', `didCommit ${identifier.lid}`]);

const user2 = store.peekRecord('user', '2') as User;
assert.notStrictEqual(user2, null, 'The user is in the store');
assert.strictEqual(user2?.name, 'John', 'The user has the expected name');
assert.notEqual(user2, null, 'The user is in the store');
assert.equal(user2?.name, 'John', 'The user has the expected name');
});

test('Rejecting while persisting a deletion with a deleteRecord op works as expected', async function (assert) {
Expand Down Expand Up @@ -231,8 +231,8 @@ module('Integration - deleteRecord', function (hooks) {
assert.true(user.isDeleted, 'The user is deleted');
assert.false(user.isSaving, 'The user is not saving');
assert.true(user.hasDirtyAttributes, 'The user is dirty');
assert.strictEqual(user.currentState.stateName, 'root.deleted.uncommitted', 'The user is in the correct state');
assert.strictEqual(user.dirtyType, 'deleted', 'The user is dirty with the correct type');
assert.equal(user.currentState.stateName, 'root.deleted.uncommitted', 'The user is in the correct state');
assert.equal(user.dirtyType, 'deleted', 'The user is dirty with the correct type');

const validationError: Error & {
content: { errors: JsonApiError[] };
Expand Down Expand Up @@ -261,7 +261,7 @@ module('Integration - deleteRecord', function (hooks) {
assert.ok(false, 'The promise should reject');
} catch (e: unknown) {
assert.true(e instanceof Error, 'The error is an error');
assert.strictEqual((e as Error).message, '405 | Not Authorized', 'The error has the expected error message');
assert.equal((e as Error).message, '405 | Not Authorized', 'The error has the expected error message');
assert.true(
Array.isArray((e as { content: { errors: JsonApiError[] } })?.content?.errors),
'The error has an errors array'
Expand All @@ -271,9 +271,9 @@ module('Integration - deleteRecord', function (hooks) {
assert.false(user.isDestroying, 'The user is not destroying');
assert.false(user.isDestroyed, 'The user is not destroyed');
assert.true(user.hasDirtyAttributes, 'The user is still dirty');
assert.strictEqual(user.currentState.stateName, 'root.deleted.invalid', 'The user is in the correct state');
assert.strictEqual(user.dirtyType, 'deleted', 'The user is still dirty');
assert.strictEqual(user.adapterError?.message, '405 | Not Authorized', 'The user has the expected error message');
assert.equal(user.currentState.stateName, 'root.deleted.invalid', 'The user is in the correct state');
assert.equal(user.dirtyType, 'deleted', 'The user is still dirty');
assert.equal(user.adapterError?.message, '405 | Not Authorized', 'The user has the expected error message');
assert.true(user.isDeleted, 'The user is still deleted');
assert.false(user.isSaving, 'The user is no longer saving');

Expand Down
12 changes: 6 additions & 6 deletions tests/builders/tests/integration/update-record-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { module, test } from '@warp-drive/diagnostic';

import { setupTest } from 'ember-qunit';
import { setupTest } from '@ember-data/unpublished-test-infra/test-support/test-helpers';

import JSONAPICache from '@ember-data/json-api';
import { updateRecord } from '@ember-data/json-api/request';
Expand Down Expand Up @@ -134,7 +134,7 @@ module('Integration - updateRecord', function (hooks) {

await promise;

assert.strictEqual(user.name, 'James Thoburn', 'The user is updated from the response');
assert.equal(user.name, 'James Thoburn', 'The user is updated from the response');
assert.false(user.hasDirtyAttributes, 'The user is no longer dirty');
assert.false(user.isSaving, 'The user is no longer saving');

Expand Down Expand Up @@ -227,7 +227,7 @@ module('Integration - updateRecord', function (hooks) {
assert.ok(false, 'The promise should reject');
} catch (e: unknown) {
assert.true(e instanceof Error, 'The error is an error');
assert.strictEqual((e as Error).message, 'Something went wrong', 'The error has the expected error message');
assert.equal((e as Error).message, 'Something went wrong', 'The error has the expected error message');
assert.true(
Array.isArray((e as { content: { errors: JsonApiError[] } })?.content?.errors),
'The error has an errors array'
Expand All @@ -246,8 +246,8 @@ module('Integration - updateRecord', function (hooks) {
message: string;
}>;

assert.strictEqual(nameErrors.length, 1, 'The user has the expected number of errors');
assert.strictEqual(
assert.equal(nameErrors.length, 1, 'The user has the expected number of errors');
assert.equal(
nameErrors[0]?.message,
'Name must be capitalized',
'The user has the expected error for the field'
Expand Down
Loading

0 comments on commit 5f78d66

Please sign in to comment.