Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add site-profile api service. #3181

Merged
merged 2 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions refinery/ui/source/js/commons/services/site-profile-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Site Profile V2 Service
* @namespace siteProfileV2Service
* @desc Service to get and update site_profile fields via site_profile v2 api.
* @memberOf refineryApp
*/
(function () {
'use strict';
angular
.module('refineryApp')
.factory('siteProfileService', siteProfileService);

siteProfileService.$inject = ['$resource', 'settings'];

function siteProfileService ($resource, settings) {
var siteProfile = $resource(
settings.appRoot + settings.refineryApiV2 + '/site_profile/',
{},
{
query: {
method: 'GET'
},
partial_update: {
method: 'PATCH'
}
}
);

return siteProfile;
}
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

describe('Common.service.siteProfileV2Service: unit tests', function () {
var httpBackend;
var scope;
var service;
var siteProfile;
var refinerySettings;

beforeEach(module('refineryApp'));
beforeEach(inject(function (
$httpBackend,
$rootScope,
siteProfileService,
settings
) {
refinerySettings = settings;
httpBackend = $httpBackend;
scope = $rootScope;
service = siteProfileService;

siteProfile = {
twitter_username: 'mockTwitterName',
site_videos: '[{source_id:"yt_3452", source:"youtube", caption:"Analysis"}]',
intro_markdown: 'Intro to the platform.',
about_markdown: 'About the platform'
};
}));

describe('Service', function () {
it('should be defined', function () {
expect(service).toBeDefined();
});

it('should be a method', function () {
expect(typeof service).toEqual('function');
});

it('query should return a resolving promise', function () {
httpBackend
.expectGET(
refinerySettings.appRoot +
refinerySettings.refineryApiV2 +
'/site_profile/'
).respond(200, siteProfile);

var results;
var promise = service.query().$promise
.then(function (response) {
results = response;
});
expect(typeof promise.then).toEqual('function');
httpBackend.flush();
scope.$digest();
expect(results.twitter_username).toEqual(siteProfile.twitter_username);
});

it('patch should return a resolving promise', function () {
var param = { intro_markdown: 'New intro paragraph.' };
siteProfile.intro_markdown = param.intro_markdown;
var mockResponse = { status: 202, data: siteProfile };
httpBackend
.expectPATCH(
refinerySettings.appRoot +
refinerySettings.refineryApiV2 +
'/site_profile/',
param
).respond(202, mockResponse);

var results;
var promise = service.partial_update(param).$promise
.then(function (response) {
results = response;
});

expect(typeof promise.then).toEqual('function');
httpBackend.flush();
scope.$digest();
expect(results.status).toEqual(mockResponse.status);
expect(results.data.intro_markdown).toEqual(param.intro_markdown);
});
});
});