Skip to content

Commit 8d42516

Browse files
committedNov 16, 2021
patch: make setLibrary function able to seprate set library name and version
1 parent 9632966 commit 8d42516

File tree

2 files changed

+7
-44
lines changed

2 files changed

+7
-44
lines changed
 

‎src/amplitude-client.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -1908,30 +1908,13 @@ AmplitudeClient.prototype.__VERSION__ = function getVersion() {
19081908
* @param {string} name - Custom library name
19091909
* @param {string} version - Custom library version
19101910
*/
1911-
AmplitudeClient.prototype.setLibrary = function setLibrary(name, version) {
1911+
AmplitudeClient.prototype.setLibrary = function setLibrary(
1912+
name = this.options.libraryName,
1913+
version = this.options.libraryVersion,
1914+
) {
19121915
this.options.library = { name: name, version: version };
19131916
};
19141917

1915-
/**
1916-
* Sets the library name.
1917-
* @public
1918-
* @param {string} libraryName - the library name.
1919-
* @example amplitudeClient.setLibraryName('my_library_name');
1920-
*/
1921-
AmplitudeClient.prototype.setLibraryName = function setLibraryName(libraryName) {
1922-
this.options.library.name = libraryName;
1923-
};
1924-
1925-
/**
1926-
* Sets the library Version.
1927-
* @public
1928-
* @param {string} userId - the library version.
1929-
* @example amplitudeClient.setLibraryVersion('1.0.0');
1930-
*/
1931-
AmplitudeClient.prototype.setLibraryVersion = function setLibraryVersion(libraryVersion) {
1932-
this.options.library.version = libraryVersion;
1933-
};
1934-
19351918
/**
19361919
* Determines whether or not to push call to this._q or invoke it
19371920
* @private

‎test/amplitude-client.js

+3-23
Original file line numberDiff line numberDiff line change
@@ -4172,6 +4172,7 @@ describe('AmplitudeClient', function () {
41724172
beforeEach(function () {
41734173
reset();
41744174
});
4175+
41754176
it('should use default library options', function () {
41764177
amplitude.init(apiKey);
41774178
amplitude.logEvent('Event Type 1');
@@ -4189,41 +4190,20 @@ describe('AmplitudeClient', function () {
41894190
assert.equal(version, '1.0-test');
41904191
});
41914192

4192-
it('should change library when set with method', function () {
4193-
amplitude.init(apiKey);
4194-
amplitude.setLibrary('test-library', '1.0-test');
4195-
amplitude.logEvent('Event Type 2');
4196-
4197-
const { name, version } = JSON.parse(queryString.parse(server.requests[0].requestBody).e)[0].library;
4198-
4199-
assert.equal(name, 'test-library');
4200-
assert.equal(version, '1.0-test');
4201-
});
4202-
});
4203-
4204-
describe('libraryName', function () {
4205-
beforeEach(function () {
4206-
reset();
4207-
});
42084193
it('should use the customize library name and default library version', function () {
42094194
amplitude.init(apiKey);
4210-
amplitude.setLibraryName('test-library');
4195+
amplitude.setLibrary('test-library', undefined);
42114196
amplitude.logEvent('Event Type');
42124197

42134198
const { name, version } = JSON.parse(queryString.parse(server.requests[0].requestBody).e)[0].library;
42144199

42154200
assert.equal(name, 'test-library');
42164201
assert.equal(version, amplitude.options.library.version);
42174202
});
4218-
});
42194203

4220-
describe('libraryVersion', function () {
4221-
beforeEach(function () {
4222-
reset();
4223-
});
42244204
it('should use the customize library version and default library name', function () {
42254205
amplitude.init(apiKey);
4226-
amplitude.setLibraryVersion('1.0-test');
4206+
amplitude.setLibrary(undefined, '1.0-test');
42274207
amplitude.logEvent('Event Type');
42284208

42294209
const { name, version } = JSON.parse(queryString.parse(server.requests[0].requestBody).e)[0].library;

0 commit comments

Comments
 (0)