Skip to content

Commit

Permalink
Adds Timeout Tests
Browse files Browse the repository at this point in the history
This commit adds timeout tests to all applicable methods.

Signed-off-by: Lui de la Parra <lui@mutesymphony.com>
  • Loading branch information
Luidog committed Oct 19, 2018
1 parent f8dc2ca commit 3bb145d
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 235 deletions.
385 changes: 209 additions & 176 deletions src/client.model.js

Large diffs are not rendered by default.

57 changes: 9 additions & 48 deletions tests/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,19 @@ describe('Agent Configuration Capabilities', () => {
.and.property('agent').to.be.to.be.undefined;
});

it('adjusts the agent protocol according to the server', () => {
it('should not create an agent unless one is defined', () => {
let client = Filemaker.create({
application: process.env.APPLICATION,
server: process.env.SERVER.replace('https://', 'http://'),
server: process.env.SERVER,
user: process.env.USERNAME,
password: process.env.PASSWORD,
timeout: 5000
password: process.env.PASSWORD
});
return expect(client.save())
.to.eventually.be.a('object')
.that.has.all.keys(
'_schema',
'connection',
'_id',
'data',
'agent',
'name',
'application',
'server',
'version'
)
.and.property('agent')
.to.be.a('object')
.to.have.all.keys(
'_schema',
'agent',
'global',
'protocol',
'proxy',
'timeout'
)
.and.property('protocol')
.to.equal('http');
return expect(
client
.save()
.then(client => client.list(process.env.LAYOUT, { limit: 1 }))
.then(response => global.AGENTS)
).to.eventually.be.undefined;
});

it('adjusts the request protocol according to the server', () => {
Expand Down Expand Up @@ -200,25 +180,6 @@ describe('Agent Configuration Capabilities', () => {
.to.have.any.keys('rejectUnauthorized');
});

it('should use a created request agent', () => {
let client = Filemaker.create({
application: process.env.APPLICATION,
server: process.env.SERVER,
user: process.env.USERNAME,
password: process.env.PASSWORD,
agent: { rejectUnauthorized: true }
});
return expect(
client
.save()
.then(client => client.list(process.env.LAYOUT, { limit: 1 }))
)
.to.eventually.be.an('object')
.that.has.all.keys('data')
.and.property('data')
.to.be.a('array');
});

it('should use a created request agent', () => {
let client = Filemaker.create({
application: process.env.APPLICATION,
Expand Down
12 changes: 12 additions & 0 deletions tests/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ describe('Create Capabilities', () => {
.that.has.all.keys('recordId', 'modId');
});

it('should allow you to specify a timeout', () => {
return expect(
client
.create(
process.env.LAYOUT,
{ name: 'Han Solo' },
{ request: { timeout: 10 } }
)
.catch(error => error)
).to.eventually.be.an('error');
});

it('should create FileMaker records using fieldData', () => {
return expect(
client.create(process.env.LAYOUT, { fieldData: { name: 'Han Solo' } })
Expand Down
13 changes: 13 additions & 0 deletions tests/delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ describe('Delete Capabilities', () => {
.then(response => client.delete(process.env.LAYOUT, response.recordId))
).to.eventually.be.a('object'));

it('should allow you to specify a timeout', () => {
return expect(
client
.create(process.env.LAYOUT, { name: 'Darth Vader' })
.then(response =>
client.delete(process.env.LAYOUT, response.recordId, {
request: { timeout: 10 }
})
)
.catch(error => error)
).to.eventually.be.an('error');
});

it('should trigger scripts via an array when deleting records.', () =>
expect(
client
Expand Down
20 changes: 20 additions & 0 deletions tests/edit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ describe('Edit Capabilities', () => {
);
});

it('should allow you to specify a timeout', () => {
return expect(
client
.create(process.env.LAYOUT, { name: 'Darth Vader' })
.then(response =>
client.edit(
process.env.LAYOUT,
response.recordId,
{
name: 'Luke Skywalker'
},
{
request: { timeout: 10 }
}
)
)
.catch(error => error)
).to.eventually.be.an('error');
});

it('should edit FileMaker records using fieldData', () => {
client.create(process.env.LAYOUT, { name: 'Obi-Wan' }).then(response =>
expect(
Expand Down
13 changes: 13 additions & 0 deletions tests/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ describe('Get Capabilities', () => {
.that.has.all.keys('data');
});

it('should allow you to specify a timeout', () => {
return expect(
client
.create(process.env.LAYOUT, { name: 'Darth Vader' })
.then(response =>
client.get(process.env.LAYOUT, response.recordId, {
request: { timeout: 10 }
})
)
.catch(error => error)
).to.eventually.be.an('error');
});

it('should reject get requests that do not specify a recordId', () => {
return expect(
client
Expand Down
13 changes: 13 additions & 0 deletions tests/globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ describe('Global Capabilities', () => {
).to.eventually.be.a('object');
});

it('should allow you to specify a timeout', () => {
return expect(
client
.globals(
{ 'Globals::ship': 'Millenium Falcon' },
{
request: { timeout: 10 }
}
)
.catch(error => error)
).to.eventually.be.an('error');
});

it('should reject with a message and code if it fails to set a global', () => {
return expect(
client.globals({ ship: 'Millenium Falcon' }).catch(error => error)
Expand Down
24 changes: 16 additions & 8 deletions tests/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ describe('List Capabilities', () => {
.and.property('data');
});

it('should allow you to specify a timeout', () => {
return expect(
client
.list(process.env.LAYOUT, {
request: { timeout: 10 }
})
.catch(error => error)
).to.eventually.be.an('error');
});

it('should allow you use parameters to modify the list response', () => {
return expect(client.list(process.env.LAYOUT, { _limit: '2' }))
.to.eventually.be.a('object')
Expand Down Expand Up @@ -178,14 +188,12 @@ describe('List Capabilities', () => {
it('should remove an expired token', () => {
client.connection.token = `${client.connection.token}-error`;
return expect(
client
.list(process.env.LAYOUT, { limit: 2, offset: 2 })
.catch(error => {
let errorWithToken = Object.assign(error, {
token: client.connection.token
});
return errorWithToken;
})
client.list(process.env.LAYOUT, { limit: 2, offset: 2 }).catch(error => {
let errorWithToken = Object.assign(error, {
token: client.connection.token
});
return errorWithToken;
})
)
.to.eventually.be.an('object')
.that.has.all.keys('code', 'message', 'token')
Expand Down
20 changes: 20 additions & 0 deletions tests/script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ describe('Script Capabilities', () => {
.that.has.all.keys('result');
});

it('should allow you to specify a timeout', () => {
return expect(
client
.script(
process.env.LAYOUT,
'FMS Triggered Script',
{
name: 'han',
number: 102,
object: { child: 'ben' },
array: ['leia', 'chewbacca']
},
{
request: { timeout: 10 }
}
)
.catch(error => error)
).to.eventually.be.an('error');
});

it('should allow you to trigger a script specifying a string as a parameter', () => {
return expect(
client.script(process.env.LAYOUT, 'FMS Triggered Script', 'string-here')
Expand Down
75 changes: 72 additions & 3 deletions tests/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { expect, should } = require('chai');

/* eslint-enable */

const fs = require('fs');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const environment = require('dotenv');
Expand Down Expand Up @@ -49,6 +50,22 @@ describe('File Upload Capabilities', () => {
.catch(error => done());
});

it('should allow you to specify a timeout', () => {
return expect(
client
.upload(
'./assets/placeholder.md',
process.env.LAYOUT,
'image',
undefined,
{
request: { timeout: 10 }
}
)
.catch(error => error)
).to.eventually.be.an('error');
});

it('should allow you to upload a file to a new record', () => {
return expect(
client.upload('./assets/placeholder.md', process.env.LAYOUT, 'image')
Expand All @@ -58,21 +75,45 @@ describe('File Upload Capabilities', () => {
.and.property('modId', '1');
});

it('should allow you to upload a buffer to a new record', () => {
const buffer = fs.readFileSync('./assets/placeholder.md');
return expect(
client
.create(process.env.LAYOUT, { name: 'Han Solo' })
.then(record => client.upload(buffer, process.env.LAYOUT, 'image'))
)
.to.eventually.be.a('object')
.that.has.all.keys('modId', 'recordId')
.and.property('modId', '1');
});

it('should allow you to upload a file to a specific container repetition', () => {
return expect(
client.upload(
'./assets/placeholder.md',
process.env.LAYOUT,
'image',
undefined,
2
{ fieldRepetition: 2 }
)
)
.to.eventually.be.a('object')
.that.has.all.keys('modId', 'recordId')
.and.property('modId', '1');
});

it('should allow you to upload a buffer to a specific container repetition', () => {
const buffer = fs.readFileSync('./assets/placeholder.md');
return expect(
client.upload(buffer, process.env.LAYOUT, 'image', undefined, {
fieldRepetition: 2
})
)
.to.eventually.be.a('object')
.that.has.all.keys('modId', 'recordId')
.and.property('modId', '1');
});

it('should reject with a message if it can not find the file to upload', () => {
return expect(
client
Expand Down Expand Up @@ -101,6 +142,20 @@ describe('File Upload Capabilities', () => {
.and.property('modId', '1');
});

it('should allow you to upload a file to a specific record', () => {
const buffer = fs.readFileSync('./assets/placeholder.md');
return expect(
client
.create(process.env.LAYOUT, { name: 'Han Solo' })
.then(record =>
client.upload(buffer, process.env.LAYOUT, 'image', record.recordId)
)
)
.to.eventually.be.a('object')
.that.has.all.keys('modId', 'recordId')
.and.property('modId', '1');
});

it('should allow you to upload a file to a specific record container repetition', () => {
return expect(
client
Expand All @@ -111,12 +166,26 @@ describe('File Upload Capabilities', () => {
process.env.LAYOUT,
'image',
record.recordId,
2
{ fieldRepetition: 2 }
)
)
)
.to.eventually.be.a('object')
.that.has.all.keys('modId','recordId')
.that.has.all.keys('modId', 'recordId')
.and.property('modId', '1');
});

it('should allow you to upload a buffer to a specific record container repetition', () => {
const buffer = fs.readFileSync('./assets/placeholder.md');
return expect(
client.create(process.env.LAYOUT, { name: 'Han Solo' }).then(record =>
client.upload(buffer, process.env.LAYOUT, 'image', record.recordId, {
fieldRepetition: 2
})
)
)
.to.eventually.be.a('object')
.that.has.all.keys('modId', 'recordId')
.and.property('modId', '1');
});

Expand Down

0 comments on commit 3bb145d

Please sign in to comment.