From 3eae668e64eecc0c477ee800a1977e787e49d4a8 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 24 Oct 2016 12:17:17 +0800 Subject: [PATCH] Set up pretender inside test file. --- .../fixtures/user-search_fixtures.js.es6 | 3 - .../helpers/create-pretender.js.es6 | 5 -- test/javascripts/lib/user-search-test.js.es6 | 57 ++++++++++++++++++- 3 files changed, 56 insertions(+), 9 deletions(-) delete mode 100644 test/javascripts/fixtures/user-search_fixtures.js.es6 diff --git a/test/javascripts/fixtures/user-search_fixtures.js.es6 b/test/javascripts/fixtures/user-search_fixtures.js.es6 deleted file mode 100644 index 2923548d85d..00000000000 --- a/test/javascripts/fixtures/user-search_fixtures.js.es6 +++ /dev/null @@ -1,3 +0,0 @@ -export default { -"/search/user/search?term=team&include_mentionable_groups=true": {"users":[{"username":"TeaMoe","name":"TeaMoe","avatar_template":"https://avatars.discourse.org/v3/letter/t/41988e/{size}.png"},{"username":"TeamOneJ","name":"J Cobb","avatar_template":"https://avatars.discourse.org/v3/letter/t/3d9bf3/{size}.png"},{"username":"kudos","name":"Team Blogeto.com","avatar_template":"/user_avatar/meta.discourse.org/kudos/{size}/62185_1.png"},{"username":"RosieLinda","name":"Linda Teaman","avatar_template":"https://avatars.discourse.org/v3/letter/r/bc8723/{size}.png"},{"username":"legalatom","name":"Team LegalAtom","avatar_template":"https://avatars.discourse.org/v3/letter/l/a9a28c/{size}.png"},{"username":"dzsat_team","name":"Dz Sat Dz Sat","avatar_template":"https://avatars.discourse.org/v3/letter/d/eb9ed0/{size}.png"}],"groups":[{"name":"team","usernames":[]}]} -}; diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index 6414216ee81..7e815029b6b 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -90,11 +90,6 @@ export default function() { return response({}); }); - this.get('/users/search/users', () => { - return response(fixturesByUrl['/search/user/search?term=team&include_mentionable_groups=true']); - }); - - this.put('/users/eviltrout', () => response({ user: {} })); this.get("/t/280.json", () => response(fixturesByUrl['/t/280/1.json'])); diff --git a/test/javascripts/lib/user-search-test.js.es6 b/test/javascripts/lib/user-search-test.js.es6 index c9931127970..52ac44b46be 100644 --- a/test/javascripts/lib/user-search-test.js.es6 +++ b/test/javascripts/lib/user-search-test.js.es6 @@ -1,6 +1,61 @@ import userSearch from 'discourse/lib/user-search'; -module("lib:user-search"); +module("lib:user-search", { + setup() { + const response = (object) => { + return [ + 200, + {"Content-Type": "application/json"}, + object + ]; + }; + + server.get('/users/search/users', () => { + return response( + { + users: [ + { + "username": "TeaMoe", + "name": "TeaMoe", + "avatar_template": "https://avatars.discourse.org/v3/letter/t/41988e/{size}.png" + }, + { + "username": "TeamOneJ", + "name": "J Cobb", + "avatar_template": + "https://avatars.discourse.org/v3/letter/t/3d9bf3/{size}.png" + }, + { + "username": "kudos", + "name": "Team Blogeto.com", + "avatar_template": "/user_avatar/meta.discourse.org/kudos/{size}/62185_1.png" + }, + { + "username": "RosieLinda", + "name": "Linda Teaman", + "avatar_template": "https://avatars.discourse.org/v3/letter/r/bc8723/{size}.png" + }, + { + "username": "legalatom", + "name": "Team LegalAtom", + "avatar_template": "https://avatars.discourse.org/v3/letter/l/a9a28c/{size}.png" + }, + { + "username": "dzsat_team", + "name": "Dz Sat Dz Sat", + "avatar_template": "https://avatars.discourse.org/v3/letter/d/eb9ed0/{size}.png" + } + ], + groups: [ + { + "name": "team", + "usernames": [] + } + ] + }); + }); + } +}); test("it places groups unconditionally for exact match", function() { return userSearch({term: 'team'}).then((results)=>{