mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Ported groups service to user new api v3 and ported dependent controllers (#7108)
* Ported groups service to user new api v3 and ported dependent controllers * Remove and extra remove inviation code. Fixed group service caching and update group service tests * Fixed test logic and added party cache support * Added promise rejections and updated http interceptor
This commit is contained in:
committed by
Matteo Pagliazzi
parent
f2d5c921ed
commit
ea490c9a1f
@@ -23,6 +23,53 @@ describe('Groups Controller', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("isMemberOfPendingQuest", function() {
|
||||
var party;
|
||||
var partyStub;
|
||||
|
||||
beforeEach(function () {
|
||||
party = specHelper.newGroup({
|
||||
_id: "unique-party-id",
|
||||
type: 'party',
|
||||
members: ['leader-id'] // Ensure we wouldn't pass automatically.
|
||||
});
|
||||
|
||||
partyStub = sandbox.stub(groups, "party", function() {
|
||||
return party;
|
||||
});
|
||||
});
|
||||
|
||||
it("returns false if group is does not have a quest", function() {
|
||||
expect(scope.isMemberOfPendingQuest(user._id, party)).to.not.be.ok;
|
||||
});
|
||||
|
||||
it("returns false if group quest has not members", function() {
|
||||
party.quest = {
|
||||
'key': 'random-key',
|
||||
};
|
||||
expect(scope.isMemberOfPendingQuest(user._id, party)).to.not.be.ok;
|
||||
});
|
||||
|
||||
it("returns false if group quest is active", function() {
|
||||
party.quest = {
|
||||
'key': 'random-key',
|
||||
'members': {},
|
||||
'active': true,
|
||||
};
|
||||
party.quest.members[user._id] = true;
|
||||
expect(scope.isMemberOfPendingQuest(user._id, party)).to.not.be.ok;
|
||||
});
|
||||
|
||||
it("returns true if user is a member of a pending quest", function() {
|
||||
party.quest = {
|
||||
'key': 'random-key',
|
||||
'members': {},
|
||||
};
|
||||
party.quest.members[user._id] = true;
|
||||
expect(scope.isMemberOfPendingQuest(user._id, party)).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
describe("isMemberOfGroup", function() {
|
||||
it("returns true if group is the user's party retrieved from groups service", function() {
|
||||
var party = specHelper.newGroup({
|
||||
@@ -31,7 +78,7 @@ describe('Groups Controller', function() {
|
||||
members: ['leader-id'] // Ensure we wouldn't pass automatically.
|
||||
});
|
||||
|
||||
var partyStub = sandbox.stub(groups,"party", function() {
|
||||
var partyStub = sandbox.stub(groups, "party", function() {
|
||||
return party;
|
||||
});
|
||||
|
||||
@@ -46,7 +93,7 @@ describe('Groups Controller', function() {
|
||||
members: [user._id]
|
||||
});
|
||||
|
||||
var myGuilds = sandbox.stub(groups,"myGuilds", function() {
|
||||
var myGuilds = sandbox.stub(groups, "myGuilds", function() {
|
||||
return [guild];
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
describe("Party Controller", function() {
|
||||
var scope, ctrl, user, User, questsService, groups, rootScope, $controller;
|
||||
var party;
|
||||
|
||||
beforeEach(function() {
|
||||
user = specHelper.newUser(),
|
||||
@@ -10,7 +11,13 @@ describe("Party Controller", function() {
|
||||
user: user,
|
||||
sync: sandbox.spy(),
|
||||
set: sandbox.spy()
|
||||
}
|
||||
};
|
||||
|
||||
party = specHelper.newGroup({
|
||||
_id: "unique-party-id",
|
||||
type: 'party',
|
||||
members: ['leader-id'] // Ensure we wouldn't pass automatically.
|
||||
});
|
||||
|
||||
module(function($provide) {
|
||||
$provide.value('User', User);
|
||||
@@ -136,6 +143,25 @@ describe("Party Controller", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("create", function() {
|
||||
var partyStub;
|
||||
|
||||
beforeEach(function () {
|
||||
partyStub = sandbox.stub(groups.Group, "create", function() {
|
||||
return party;
|
||||
});
|
||||
});
|
||||
|
||||
it("creates a new party", function() {
|
||||
var group = {
|
||||
type: 'party',
|
||||
};
|
||||
scope.create(group);
|
||||
expect(partyStub).to.be.calledOnce;
|
||||
//@TODO: Check user party console.log(User.user.party.id)
|
||||
});
|
||||
});
|
||||
|
||||
describe('questAccept', function() {
|
||||
beforeEach(function() {
|
||||
scope.group = {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
describe('groupServices', function() {
|
||||
var $httpBackend, $http, groups, user;
|
||||
var groupApiUrlPrefix = '/api/v3/groups';
|
||||
|
||||
beforeEach(function() {
|
||||
module(function($provide) {
|
||||
@@ -16,27 +17,141 @@ describe('groupServices', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('calls get groups', function() {
|
||||
$httpBackend.expectGET(groupApiUrlPrefix).respond({});
|
||||
groups.Group.getGroups();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls get group', function() {
|
||||
var gid = 1;
|
||||
$httpBackend.expectGET(groupApiUrlPrefix + '/' + gid).respond({});
|
||||
groups.Group.get(gid);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls party endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups/party').respond({});
|
||||
$httpBackend.expectGET(groupApiUrlPrefix + '/party').respond({});
|
||||
groups.Group.syncParty();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls create endpoint', function() {
|
||||
$httpBackend.expectPOST(groupApiUrlPrefix).respond({});
|
||||
groups.Group.create({});
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls update group', function() {
|
||||
var gid = 1;
|
||||
var groupDetails = { _id: gid };
|
||||
$httpBackend.expectPUT(groupApiUrlPrefix + '/' + gid).respond({});
|
||||
groups.Group.update(groupDetails);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls join group', function() {
|
||||
var gid = 1;
|
||||
$httpBackend.expectPOST(groupApiUrlPrefix + '/' + gid + '/join').respond({});
|
||||
groups.Group.join(gid);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls reject invite group', function() {
|
||||
var gid = 1;
|
||||
$httpBackend.expectPOST(groupApiUrlPrefix + '/' + gid + '/reject-invite').respond({});
|
||||
groups.Group.rejectInvite(gid);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls invite group', function() {
|
||||
var gid = 1;
|
||||
$httpBackend.expectPOST(groupApiUrlPrefix + '/' + gid + '/invite').respond({});
|
||||
groups.Group.invite(gid, [], []);
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls party endpoint when party is not cached', function() {
|
||||
$httpBackend.expectGET(groupApiUrlPrefix + '/party').respond({});
|
||||
groups.party();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls tavern endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups/habitrpg').respond({});
|
||||
it('returns party if cached', function (done) {
|
||||
var uid = 'abc';
|
||||
var party = {
|
||||
_id: uid,
|
||||
};
|
||||
groups.data.party = party;
|
||||
groups.party()
|
||||
.then(function (result) {
|
||||
expect(result).to.eql(party);
|
||||
done();
|
||||
});
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls tavern endpoint when tavern is not cached', function() {
|
||||
$httpBackend.expectGET(groupApiUrlPrefix + '/habitrpg').respond({});
|
||||
groups.tavern();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('returns tavern if cached', function (done) {
|
||||
var uid = 'abc';
|
||||
var tavern = {
|
||||
_id: uid,
|
||||
};
|
||||
groups.data.tavern = tavern;
|
||||
groups.tavern()
|
||||
.then(function (result) {
|
||||
expect(result).to.eql(tavern);
|
||||
done();
|
||||
});
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls public guilds endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups?type=public').respond([]);
|
||||
$httpBackend.expectGET(groupApiUrlPrefix + '?type=publicGuilds').respond([]);
|
||||
groups.publicGuilds();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('returns public guilds if cached', function (done) {
|
||||
var uid = 'abc';
|
||||
var publicGuilds = [
|
||||
{_id: uid},
|
||||
];
|
||||
groups.data.publicGuilds = publicGuilds;
|
||||
|
||||
groups.publicGuilds()
|
||||
.then(function (result) {
|
||||
expect(result).to.eql(publicGuilds);
|
||||
done();
|
||||
});
|
||||
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('calls my guilds endpoint', function() {
|
||||
$httpBackend.expectGET('/api/v2/groups?type=guilds').respond([]);
|
||||
$httpBackend.expectGET(groupApiUrlPrefix + '?type=privateGuilds').respond([]);
|
||||
groups.myGuilds();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it('returns my guilds if cached', function (done) {
|
||||
var uid = 'abc';
|
||||
var myGuilds = [
|
||||
{_id: uid},
|
||||
];
|
||||
groups.data.myGuilds = myGuilds;
|
||||
|
||||
groups.myGuilds()
|
||||
.then(function (myGuilds) {
|
||||
expect(myGuilds).to.eql(myGuilds);
|
||||
done();
|
||||
});
|
||||
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,6 +28,9 @@ var specHelper = {};
|
||||
|
||||
var user = {
|
||||
_id: 'unique-user-id',
|
||||
profile: {
|
||||
name: 'dummy-name',
|
||||
},
|
||||
auth: { timestamps: {} },
|
||||
stats: stats,
|
||||
items: items,
|
||||
|
||||
Reference in New Issue
Block a user