nebulab-dropbox
Version:
Client library for the Dropbox API
114 lines (89 loc) • 4.37 kB
text/coffeescript
describe 'Dropbox.File.ShareUrl', ->
describe '.parse', ->
describe 'on the /shares API example', ->
beforeEach ->
urlData = {
"url": "http://db.tt/APqhX1",
"expires": "Tue, 01 Jan 2030 00:00:00 +0000"
}
= Dropbox.File.ShareUrl.parse urlData, false
it 'parses url correctly', ->
expect().to.have.property 'url'
expect(.url).to.equal 'http://db.tt/APqhX1'
it 'parses expiresAt correctly', ->
expect().to.have.property 'expiresAt'
expect(.expiresAt).to.be.instanceOf Date
expect([
'Tue, 01 Jan 2030 00:00:00 GMT', # every sane JS platform
'Tue, 1 Jan 2030 00:00:00 UTC' # Internet Explorer
]).to.contain(.expiresAt.toUTCString())
it 'parses isDirect correctly', ->
expect().to.have.property 'isDirect'
expect(.isDirect).to.equal false
it 'parses isPreview correctly', ->
expect().to.have.property 'isPreview'
expect(.isPreview).to.equal true
it 'round-trips through toJSON / parse correctly', ->
newUrl = Dropbox.File.ShareUrl.parse .toJSON()
newUrl.toJSON() # Get _json populated for newUrl.
expect(newUrl).to.deep.equal
it 'round-trips through JSON.{stringify, parse} / parse correctly', ->
newUrl = Dropbox.File.ShareUrl.parse JSON.parse(JSON.stringify())
newUrl.toJSON() # Get _json populated for newUrl.
expect(newUrl).to.deep.equal
it 'supports deprecated json()', ->
expect(.toJSON()).to.deep.equal .json()
it 'passes null through', ->
expect(Dropbox.File.ShareUrl.parse(null)).to.equal null
it 'passes undefined through', ->
expect(Dropbox.File.ShareUrl.parse(undefined)).to.equal undefined
describe 'Dropbox.File.CopyReference', ->
describe '.parse', ->
describe 'on the API example', ->
beforeEach ->
refData = {
"copy_ref": "z1X6ATl6aWtzOGq0c3g5Ng",
"expires": "Fri, 31 Jan 2042 21:01:05 +0000"
}
= Dropbox.File.CopyReference.parse refData
it 'parses tag correctly', ->
expect().to.have.property 'tag'
expect(.tag).to.equal 'z1X6ATl6aWtzOGq0c3g5Ng'
it 'parses expiresAt correctly', ->
expect().to.have.property 'expiresAt'
expect(.expiresAt).to.be.instanceOf Date
expect([
'Fri, 31 Jan 2042 21:01:05 GMT', # every sane JS platform
'Fri, 31 Jan 2042 21:01:05 UTC' # Internet Explorer
]).to.contain(.expiresAt.toUTCString())
it 'round-trips through toJSON / parse correctly', ->
newRef = Dropbox.File.CopyReference.parse .json()
expect(newRef).to.deep.equal
it 'round-trips through JSON.{stringify, parse} / parse correctly', ->
newRef = Dropbox.File.CopyReference.parse JSON.parse(
JSON.stringify())
expect(newRef).to.deep.equal
it 'supports deprecated json()', ->
expect(.toJSON()).to.deep.equal .json()
describe 'on a reference string', ->
beforeEach ->
rawRef = 'z1X6ATl6aWtzOGq0c3g5Ng'
= Dropbox.File.CopyReference.parse rawRef
it 'parses tag correctly', ->
expect().to.have.property 'tag'
expect(.tag).to.equal 'z1X6ATl6aWtzOGq0c3g5Ng'
it 'parses expiresAt correctly', ->
expect().to.have.property 'expiresAt'
expect(.expiresAt).to.be.instanceOf Date
expect(.expiresAt - (new Date())).to.be.below 1000
it 'round-trips through toJSON / parse correctly', ->
newRef = Dropbox.File.CopyReference.parse .toJSON()
expect(newRef).to.deep.equal
it 'round-trips through JSON.{stringify, parse} / parse correctly', ->
newRef = Dropbox.File.CopyReference.parse JSON.parse(
JSON.stringify())
expect(newRef).to.deep.equal
it 'passes null through', ->
expect(Dropbox.File.CopyReference.parse(null)).to.equal null
it 'passes undefined through', ->
expect(Dropbox.File.CopyReference.parse(undefined)).to.equal undefined