Skip to content

Commit

Permalink
add deep equals / default value test
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed May 6, 2020
1 parent 0d33c46 commit e8282e0
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions test/serialized.objects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe(packageJson.name, () => {
before(async () => {
// Set up the express app
const apiSpec = path.join('test', 'resources', 'serialized.objects.yaml');
app = await createApp({ apiSpec }, 3005, app =>
app = await createApp({ apiSpec }, 3005, (app) =>
app.use(
`${app.basePath}`,
express
Expand All @@ -37,7 +37,7 @@ describe(packageJson.name, () => {
fooBar: '{"foo":"bar"}',
})
.expect(200)
.then(response => {
.then((response) => {
expect(response.body).to.deep.equal({
settings: {
onlyValidated: true,
Expand All @@ -58,7 +58,7 @@ describe(packageJson.name, () => {
fooBar: 'fooBar',
})
.expect(200)
.then(response => {
.then((response) => {
expect(response.body).to.deep.equal({
timestamp: 1234567890123,
fooBar: 'fooBar',
Expand All @@ -72,7 +72,7 @@ describe(packageJson.name, () => {
settings: 'this is not valid json',
})
.expect(400)
.then(response => {
.then((response) => {
expect(response.body.message).to.equal(
'request.query.settings should be object',
);
Expand All @@ -86,7 +86,7 @@ describe(packageJson.name, () => {
tag_ids: 1,
})
.expect(400)
.then(r => {
.then((r) => {
expect(r.body)
.to.have.property('message')
.that.equals('request.query.settings.tag_ids should be array');
Expand All @@ -99,7 +99,7 @@ describe(packageJson.name, () => {
tag_ids: [1],
})
.expect(200)
.then(r => {
.then((r) => {
expect(r.body).to.have.property('settings');
expect(r.body.settings)
.to.have.property('tag_ids')
Expand All @@ -110,12 +110,39 @@ describe(packageJson.name, () => {
request(app)
.get(`${app.basePath}/deep_object?settings[state]=validated`)
.expect(200)
.then(r => {
.then((r) => {
const expected = {
settings: {
state: 'validated',
},
};
expect(r.body).to.deep.equals(expected);
}));

it('should explode deepObject query params', async () =>
request(app)
.get(`${app.basePath}/deep_object?settings[state]=validated`)
.expect(200)
.then((r) => {
const expected = {
settings: {
state: 'validated',
},
};
expect(r.body).to.deep.equals(expected);
}));

it('should explode deepObject query params and use deepObject default values', async () =>
request(app)
.get(`${app.basePath}/deep_object?settings[tag_ids][0]=1`)
.expect(200)
.then((r) => {
const expected = {
settings: {
tag_ids: [1],
state: 'default',
},
};
expect(r.body).to.deep.equals(expected);
}));
});

0 comments on commit e8282e0

Please sign in to comment.