mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 02:04:53 +08:00
Add tests for our store
This commit is contained in:
@ -19,6 +19,11 @@ function success() {
|
||||
return response({ success: true });
|
||||
}
|
||||
|
||||
const _widgets = [
|
||||
{id: 123, name: 'Trout Lure'},
|
||||
{id: 124, name: 'Evil Repellant'}
|
||||
];
|
||||
|
||||
export default function() {
|
||||
var server = new Pretender(function() {
|
||||
|
||||
@ -84,6 +89,21 @@ export default function() {
|
||||
|
||||
this.delete('/posts/:post_id', success);
|
||||
this.put('/posts/:post_id/recover', success);
|
||||
|
||||
this.get('/widgets/:widget_id', function(request) {
|
||||
const w = _widgets.findBy('id', parseInt(request.params.widget_id));
|
||||
if (w) {
|
||||
return response({widget: w});
|
||||
} else {
|
||||
return response(404);
|
||||
}
|
||||
});
|
||||
|
||||
this.get('/widgets', function() {
|
||||
return response({ widgets: _widgets });
|
||||
});
|
||||
|
||||
this.delete('/widgets/:widget_id', success);
|
||||
});
|
||||
|
||||
|
||||
|
19
test/javascripts/helpers/create-store.js.es6
Normal file
19
test/javascripts/helpers/create-store.js.es6
Normal file
@ -0,0 +1,19 @@
|
||||
import Store from "discourse/models/store";
|
||||
import RestAdapter from 'discourse/adapters/rest';
|
||||
|
||||
let _restAdapter;
|
||||
export default function() {
|
||||
return Store.create({
|
||||
container: {
|
||||
lookup(type) {
|
||||
if (type === "adapter:rest") {
|
||||
_restAdapter = _restAdapter || RestAdapter.create({ container: this });
|
||||
return (_restAdapter);
|
||||
}
|
||||
},
|
||||
|
||||
lookupFactory: function() { }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user