Skip to content

Commit

Permalink
convert tests to new style
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanto committed Sep 8, 2018
1 parent 83d4907 commit f11203b
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 228 deletions.
111 changes: 59 additions & 52 deletions tests/integration/-private/cache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,85 @@ import { module, test } from 'ember-qunit';
import Cache from 'ember-data-storefront/-private/cache';
import RecordQuery from 'ember-data-storefront/-private/record-query';

module('Integration | Cache test');

const mockStore = {};
module('Integration | Cache test', function(hooks) {
hooks.beforeEach(function() {
this.mockStore = {};
});

test('it can store a query with no params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(mockStore, 'post', 1);
hooks.afterEach(function() {
delete this.mockStore;
});

cache.put(query);
test('it can store a query with no params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1);

assert.equal(cache.get('post', 1), query);
});
cache.put(query);

test('it can store a query with simple params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(mockStore, 'post', 1, {
testing: 123
assert.equal(cache.get('post', 1), query);
});

cache.put(query);
test('it can store a query with simple params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
testing: 123
});

assert.equal(cache.get('post', 1, { testing: 123 }), query);
});
cache.put(query);

test("the order of the params doesn't matter", function(assert) {
let cache = new Cache();
let query = new RecordQuery(mockStore, 'post', 1, {
key1: 'A',
key2: 'B'
assert.equal(cache.get('post', 1, { testing: 123 }), query);
});

cache.put(query);
test("the order of the params doesn't matter", function(assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
key1: 'A',
key2: 'B'
});

let cachedQuery = cache.get('post', 1, {
key2: 'B',
key1: 'A'
});
assert.equal(cachedQuery, query);
});
cache.put(query);

test('it can store a query with nested params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(mockStore, 'post', 1, {
filter: {
testing: 123
}
let cachedQuery = cache.get('post', 1, {
key2: 'B',
key1: 'A'
});
assert.equal(cachedQuery, query);
});

cache.put(query);
test('it can store a query with nested params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
filter: {
testing: 123
}
});

assert.equal(cache.get('post', 1, { filter: { testing: 123 } }), query);
});
cache.put(query);

test('it can store a query with boolean params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(mockStore, 'post', 1, {
foo: true,
bar: false
assert.equal(cache.get('post', 1, { filter: { testing: 123 } }), query);
});

cache.put(query);
test('it can store a query with boolean params', function(assert) {
let cache = new Cache();
let query = new RecordQuery(this.mockStore, 'post', 1, {
foo: true,
bar: false
});

assert.equal(cache.get('post', 1, { foo: true, bar: false }), query);
});
cache.put(query);

test('it should be able to get all queries out of the cache', function(assert) {
let cache = new Cache();
let query1 = new RecordQuery(mockStore, 'post', 1);
let query2 = new RecordQuery(mockStore, 'post', 2);
assert.equal(cache.get('post', 1, { foo: true, bar: false }), query);
});

cache.put(query1);
cache.put(query2);
test('it should be able to get all queries out of the cache', function(assert) {
let cache = new Cache();
let query1 = new RecordQuery(this.mockStore, 'post', 1);
let query2 = new RecordQuery(this.mockStore, 'post', 2);

cache.put(query1);
cache.put(query2);

assert.deepEqual(cache.all(), [query1, query2]);
});

assert.deepEqual(cache.all(), [query1, query2]);
});
Loading

0 comments on commit f11203b

Please sign in to comment.