mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:01:14 +08:00
Remove ajax stubbing from post-stream tests
This commit is contained in:
@ -731,20 +731,16 @@ const PostStream = RestModel.extend({
|
|||||||
loadIntoIdentityMap(postIds) {
|
loadIntoIdentityMap(postIds) {
|
||||||
// If we don't want any posts, return a promise that resolves right away
|
// If we don't want any posts, return a promise that resolves right away
|
||||||
if (Em.isEmpty(postIds)) {
|
if (Em.isEmpty(postIds)) {
|
||||||
return Ember.RSVP.resolve();
|
return Ember.RSVP.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = "/t/" + this.get('topic.id') + "/posts.json",
|
const url = "/t/" + this.get('topic.id') + "/posts.json";
|
||||||
data = { post_ids: postIds },
|
const data = { post_ids: postIds };
|
||||||
postStream = this;
|
|
||||||
|
|
||||||
const store = this.store;
|
const store = this.store;
|
||||||
return Discourse.ajax(url, {data: data}).then(function(result) {
|
return Discourse.ajax(url, {data: data}).then(result => {
|
||||||
const posts = Em.get(result, "post_stream.posts");
|
const posts = Em.get(result, "post_stream.posts");
|
||||||
if (posts) {
|
if (posts) {
|
||||||
posts.forEach(function (p) {
|
posts.forEach(p => this.storePost(store.createRecord('post', p)));
|
||||||
postStream.storePost(store.createRecord('post', p));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -153,6 +153,16 @@ export default function() {
|
|||||||
slug: request.params.slug } });
|
slug: request.params.slug } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.get('/t/:topic_id/posts.json', request => {
|
||||||
|
const postIds = request.queryParams.post_ids;
|
||||||
|
const posts = postIds.map(p => ({id: parseInt(p), post_number: parseInt(p) }));
|
||||||
|
return response(200, { post_stream: { posts } });
|
||||||
|
});
|
||||||
|
|
||||||
|
this.get('/posts/:post_id/reply-history.json', () => {
|
||||||
|
return response(200, [ { id: 2222, post_number: 2222 } ]);
|
||||||
|
});
|
||||||
|
|
||||||
this.post('/posts', function(request) {
|
this.post('/posts', function(request) {
|
||||||
const data = parsePostData(request.requestBody);
|
const data = parsePostData(request.requestBody);
|
||||||
|
|
||||||
|
@ -302,47 +302,28 @@ test("identity map", function() {
|
|||||||
deepEqual(postStream.listUnloadedIds([1, 2, 3, 4]), [2, 4], "it only returns unloaded posts");
|
deepEqual(postStream.listUnloadedIds([1, 2, 3, 4]), [2, 4], "it only returns unloaded posts");
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTestDiscourse("loadIntoIdentityMap with no data", function() {
|
test("loadIntoIdentityMap with no data", () => {
|
||||||
const postStream = buildStream(1234);
|
buildStream(1234).loadIntoIdentityMap([]).then(result => {
|
||||||
expect(1);
|
equal(result.length, 0, 'requesting no posts produces no posts');
|
||||||
|
|
||||||
sandbox.stub(Discourse, "ajax");
|
|
||||||
postStream.loadIntoIdentityMap([]).then(function() {
|
|
||||||
ok(!Discourse.ajax.calledOnce, "an empty array returned a promise yet performed no ajax request");
|
|
||||||
start();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTestDiscourse("loadIntoIdentityMap with post ids", function() {
|
test("loadIntoIdentityMap with post ids", function() {
|
||||||
const postStream = buildStream(1234);
|
const postStream = buildStream(1234);
|
||||||
expect(1);
|
|
||||||
|
|
||||||
sandbox.stub(Discourse, "ajax").returns(Ember.RSVP.resolve({
|
|
||||||
post_stream: {
|
|
||||||
posts: [{id: 10, post_number: 10}]
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
postStream.loadIntoIdentityMap([10]).then(function() {
|
postStream.loadIntoIdentityMap([10]).then(function() {
|
||||||
present(postStream.findLoadedPost(10), "it adds the returned post to the store");
|
present(postStream.findLoadedPost(10), "it adds the returned post to the store");
|
||||||
start();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTestDiscourse("loading a post's history", function() {
|
test("loading a post's history", function() {
|
||||||
const postStream = buildStream(1234);
|
const postStream = buildStream(1234);
|
||||||
const store = postStream.store;
|
const store = postStream.store;
|
||||||
expect(3);
|
|
||||||
|
|
||||||
const post = store.createRecord('post', {id: 4321});
|
const post = store.createRecord('post', {id: 4321});
|
||||||
const secondPost = store.createRecord('post', {id: 2222});
|
|
||||||
|
|
||||||
sandbox.stub(Discourse, "ajax").returns(Ember.RSVP.resolve([secondPost]));
|
|
||||||
postStream.findReplyHistory(post).then(function() {
|
postStream.findReplyHistory(post).then(function() {
|
||||||
ok(Discourse.ajax.calledOnce, "it made the ajax request");
|
|
||||||
present(postStream.findLoadedPost(2222), "it stores the returned post in the identity map");
|
present(postStream.findLoadedPost(2222), "it stores the returned post in the identity map");
|
||||||
present(post.get('replyHistory'), "it sets the replyHistory attribute for the post");
|
present(post.get('replyHistory'), "it sets the replyHistory attribute for the post");
|
||||||
start();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user