Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed helper.js in test cases #59

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ Creating a functional `dbox` client is a four step process.
### Step 1

var dbox = require("dbox")
var app = dbox.app({ "app_key": "umdez34678ck01fx", "app_secret": "tjm89017sci88o6" })
var app = dbox.app({ "app_key": "umdez34678ck01fx", "app_secret": "tjm89017sci88o6"[, "root": "sandbox"] })

_NB_: the root parameter is to change between the two different dropbox app types there are. `sandbox` means 'App folder' and `dropbox` means 'Full Dropbox', default is `sandbox`.

### Step 2

Expand Down
1 change: 0 additions & 1 deletion dbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,3 @@ exports.app = function(config){
}

}

1 change: 1 addition & 0 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("all", function(){
var client, ref;

before(function(done){
this.timeout(20000); //To give the testrunner time for accepting the dropbox access
helpers.auth(app, function(access_token){
client = app.client(access_token)
done()
Expand Down
3 changes: 2 additions & 1 deletion test/config/app.json.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"app_key": "",
"app_secret": ""
"app_secret": "",
"root": "sandbox"
}
44 changes: 26 additions & 18 deletions test/config/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ var fs = require("fs")
var prompt = require("prompt")

exports.auth = function(app, callback){
var token = JSON.parse(fs.readFileSync(__dirname + "/access_token.json"))
var client = app.client(token)
client.account(function(status, account){
if(status == 200){
callback(token)
}else{
app.requesttoken(function(status, request_token){
prompt.start()
prompt.get(['please authorize application at the following url and enter when done\n' + request_token.authorize_url], function (err, result) {
if (err) { return 1 }
app.accesstoken(request_token, function(status, access_token){
fs.writeFile(__dirname + "/access_token.json", JSON.stringify(access_token), function(err){
if (err) throw err;
callback(access_token)
})
var makeNewAccessToken = function() {
app.requesttoken(function(status, request_token){
prompt.start()
prompt.get(['please authorize application at the following url and enter when done\n' + request_token.authorize_url], function (err, result) {
if (err) { return 1 }
app.accesstoken(request_token, function(status, access_token){
fs.writeFile(__dirname + "/access_token.json", JSON.stringify(access_token), function(err){
if (err) throw err;
callback(access_token)
})
})
})
}
})
})
})
}

if (fs.existsSync(__dirname + "/access_token.json")) {
var access_token = JSON.parse(fs.readFileSync(__dirname + "/access_token.json"))
var client = app.client(access_token)
client.account(function(status, account){
if(status == 200){
callback(access_token)
}else{
makeNewAccessToken();
}
})
} else {
makeNewAccessToken();
}
}