-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac970ef
commit 8c4b2e2
Showing
5 changed files
with
187 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import test from 'ava'; | ||
import Auth from './../src/auth'; | ||
|
||
var user = new Auth({ modelName: 'user', debug: true }); | ||
user.debugger.logEnabled = false; | ||
|
||
test('login works', t => { | ||
user.login(); | ||
t.is('api/login', user.debugger.data.lastUrl); | ||
}); | ||
|
||
test('logout works', t => { | ||
user.logout(); | ||
t.is('api/logout', user.debugger.data.lastUrl); | ||
}); | ||
|
||
test('check works', t => { | ||
user.check(); | ||
t.is('api/auth', user.debugger.data.lastUrl); | ||
}); | ||
|
||
test('register works', t => { | ||
user.register(); | ||
t.is('api/register', user.debugger.data.lastUrl); | ||
}); | ||
|
||
var userTwo = new Auth({ modelName: 'User', debug: true, auth: { modelPrefix: true } }); | ||
userTwo.debugger.logEnabled = false; | ||
|
||
test('modelPrefix works', t => { | ||
userTwo.register(); | ||
t.is('api/user/register', userTwo.debugger.data.lastUrl); | ||
}); | ||
|
||
var userThree = new Auth({ | ||
modelName: 'User', | ||
debug: true, | ||
auth: { modelPrefix: true } | ||
}); | ||
// user.debugger.logEnabled = false; | ||
|
||
test('modelPrefix works', t => { | ||
userThree.register(); | ||
t.is('api/user/register', userThree.debugger.data.lastUrl); | ||
}); | ||
|
||
var userFour = new Auth({ | ||
modelName: 'User', | ||
debug: true, | ||
auth: { | ||
routes: { | ||
login : 'login-user', | ||
logout : ['logout', 'user'], | ||
auth : 'authenticate', | ||
register : 'new' | ||
} | ||
} | ||
}); | ||
// user.debugger.logEnabled = false; | ||
|
||
test('changing routes works', t => { | ||
userFour.login(); | ||
t.is('api/login-user', userFour.debugger.data.lastUrl); | ||
|
||
userFour.logout(); | ||
t.is('api/logout/user', userFour.debugger.data.lastUrl); | ||
|
||
userFour.check(); | ||
t.is('api/authenticate', userFour.debugger.data.lastUrl); | ||
|
||
userFour.register(); | ||
t.is('api/new', userFour.debugger.data.lastUrl); | ||
}); | ||
|
||
var userFive = new Auth({ | ||
modelName: 'User', | ||
debug: true, | ||
auth: { | ||
methods: { | ||
login : 'get', | ||
logout : 'delete', | ||
auth : 'get', | ||
register : 'patch' | ||
} | ||
} | ||
}); | ||
// user.debugger.logEnabled = false; | ||
|
||
test('changing methods works', t => { | ||
userFive.login(); | ||
t.is('get', userFive.debugger.data.lastRequest.type); | ||
|
||
userFive.logout(); | ||
t.is('delete', userFive.debugger.data.lastRequest.type); | ||
|
||
userFive.check(); | ||
t.is('get', userFive.debugger.data.lastRequest.type); | ||
|
||
userFive.register(); | ||
t.is('patch', userFive.debugger.data.lastRequest.type); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
import test from 'ava'; | ||
import Rapid from './../src/rapid'; | ||
|
||
var Shark = new Rapid({ | ||
var shark = new Rapid({ | ||
modelName: 'shark', | ||
debug: true | ||
}); | ||
|
||
shark.debugger.logEnabled = false; | ||
|
||
test('works with basic CRUD', t => { | ||
|
||
Shark.id(23).find(); | ||
t.is('api/shark/23', Shark.debugger.data.lastUrl); | ||
shark.id(23).find(); | ||
t.is('api/shark/23', shark.debugger.data.lastUrl); | ||
|
||
Shark.id(234).save({}); | ||
t.is('api/shark/234/update', Shark.debugger.data.lastUrl); | ||
shark.id(234).save({}); | ||
t.is('api/shark/234/update', shark.debugger.data.lastUrl); | ||
|
||
Shark.id(456).destroy(); | ||
t.is('api/shark/456/destroy', Shark.debugger.data.lastUrl); | ||
shark.id(456).destroy(); | ||
t.is('api/shark/456/destroy', shark.debugger.data.lastUrl); | ||
|
||
}); | ||
|
||
test('works with other requests', t => { | ||
|
||
Shark.id(23).get(); | ||
t.is('api/shark/23', Shark.debugger.data.lastUrl); | ||
shark.id(23).get(); | ||
t.is('api/shark/23', shark.debugger.data.lastUrl); | ||
|
||
Shark.id(789).get('fish', 'are', 'friends', 'not', 'food'); | ||
t.is('api/shark/789/fish/are/friends/not/food', Shark.debugger.data.lastUrl); | ||
shark.id(789).get('fish', 'are', 'friends', 'not', 'food'); | ||
t.is('api/shark/789/fish/are/friends/not/food', shark.debugger.data.lastUrl); | ||
|
||
Shark.id(23).post('swim'); | ||
t.is('api/shark/23/swim', Shark.debugger.data.lastUrl); | ||
shark.id(23).post('swim'); | ||
t.is('api/shark/23/swim', shark.debugger.data.lastUrl); | ||
|
||
Shark.id(234).delete('eat', 'fish'); | ||
t.is('api/shark/234/eat/fish', Shark.debugger.data.lastUrl); | ||
shark.id(234).delete('eat', 'fish'); | ||
t.is('api/shark/234/eat/fish', shark.debugger.data.lastUrl); | ||
|
||
Shark.id(456).patch(); | ||
t.is('api/shark/456', Shark.debugger.data.lastUrl); | ||
shark.id(456).patch(); | ||
t.is('api/shark/456', shark.debugger.data.lastUrl); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters