Skip to content

Commit

Permalink
Add basic JSONB tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DaddyWarbucks committed Jun 25, 2024
1 parent b50d634 commit 579ffb5
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const Model = sequelize.define('people', {
status: {
type: Sequelize.STRING,
defaultValue: 'pending'
},
profile: {
type: Sequelize.JSONB
}
}, {
freezeTableName: true,
Expand Down Expand Up @@ -996,6 +999,47 @@ describe('Feathers Sequelize Service', () => {
});
expect(responseMulti).to.deep.equal([]);
});

it('can query by JSON fields', async () => {
await app.service('people').create({
name: 'Dave',
profile: { type: 'find' }
});

const found = await app.service('people').find({
query: {
'profile.type': 'find'
}
}) as any;

assert.strictEqual(found.length, 1);
assert.deepStrictEqual(found[0].profile, { type: 'find' });
});

it('Can update nested JSON fields', async () => {
const created = await app.service('people').create({
name: 'Dave',
profile: {
location: {
city: 'Memphis',
state: 'Tennessee'
}
}
});

const patched = await app.service('people').patch(created.id, {
name: 'David',
'profile.location.city': 'Nashville'
}) as any;

assert.strictEqual(patched.name, 'David');
assert.deepStrictEqual(patched.profile, {
location: {
city: 'Nashville',
state: 'Tennessee'
}
});
});
});

describe('raw Service', () => {
Expand Down Expand Up @@ -1139,6 +1183,47 @@ describe('Feathers Sequelize Service', () => {
expect(results).to.be.an('array').with.lengthOf(1);
expect(results[0]).to.be.an.instanceof(Model);
});

it('can query by JSON fields', async () => {
await app.service('people').create({
name: 'Dave',
profile: { type: 'find' }
});

const found = await app.service('people').find({
query: {
'profile.type': 'find'
}
}) as any;

assert.strictEqual(found.length, 1);
assert.deepStrictEqual(found[0].profile, { type: 'find' });
});

it('Can update nested JSON fields', async () => {
const created = await app.service('people').create({
name: 'Dave',
profile: {
location: {
city: 'Memphis',
state: 'Tennessee'
}
}
});

const patched = await app.service('people').patch(created.id, {
name: 'David',
'profile.location.city': 'Nashville'
}) as any;

assert.strictEqual(patched.name, 'David');
assert.deepStrictEqual(patched.profile, {
location: {
city: 'Nashville',
state: 'Tennessee'
}
});
});
});
});

Expand Down

0 comments on commit 579ffb5

Please sign in to comment.