Skip to content

Commit

Permalink
Make tests great again
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Herdmann committed May 9, 2017
1 parent eea8d9b commit e8f672a
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 207 deletions.
8 changes: 4 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ module.exports = (grunt) => {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config,
dir,
config: config,
dir: dir,
aws_s3: require('./grunt/config/aws_s3'),
bower: require('./grunt/config/bower'),
clean: require('./grunt/config/clean'),
Expand Down Expand Up @@ -116,7 +116,7 @@ module.exports = (grunt) => {
const scripts = grunt.config('scripts');

const prepare_file_names = (file_name_array) => {
return file_name_array.map(file_name => file_name.replace('deploy/', ''));
return file_name_array.map((file_name) => file_name.replace('deploy/', ''));
};

const helper_files = grunt.config.get('karma.options.files');
Expand All @@ -138,7 +138,7 @@ module.exports = (grunt) => {
'newer:coffee:dist',
'newer:coffee:test',
'newer:copy:dist_js',
'copy:test',
'newer:copy:test',
`test_prepare:${test_name}`,
'karma:test',
]);
Expand Down
4 changes: 2 additions & 2 deletions test/api/TestFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ window.TestFactory.prototype.exposeClientActors = function() {
TestFactory.client_service = new z.client.ClientService(this.client, TestFactory.storage_service);
TestFactory.client_service.logger.level = this.settings.logging_level;

TestFactory.client_repository = new z.client.ClientRepository(client_service, TestFactory.cryptography_repository);
TestFactory.client_repository = new z.client.ClientRepository(TestFactory.client_service, TestFactory.cryptography_repository);
TestFactory.client_repository.logger.level = this.settings.logging_level;
TestFactory.client_repository.init(user);
const payload = {'address': '62.96.148.44', 'class': 'desktop', 'cookie': 'webapp@2153234453@temporary@1470926647664', 'id': '132b3653b33f851f', 'label': 'Windows 10', 'location': {'lat': 52.5233, 'lon': 13.4138}, 'meta': {'is_verified': true, 'primary_key': 'local_identity'}, 'model': 'Chrome (Temporary)', 'time': '2016-10-07T16:01:42.133Z', 'type': 'temporary'};
Expand Down Expand Up @@ -228,7 +228,7 @@ window.TestFactory.prototype.exposeUserActors = function() {
TestFactory.cryptography_repository
);
TestFactory.user_repository.logger.level = this.settings.logging_level;
TestFactory.user_repository.save_user(TestFactory.client_repository.this_user(), true);
TestFactory.user_repository.save_user(TestFactory.client_repository.self_user(), true);

return TestFactory.user_repository;
});
Expand Down
3 changes: 1 addition & 2 deletions test/unit_tests/announce/AnnounceRepositorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@

'use strict';

let server = undefined;

describe('z.announce.AnnounceRepository', function() {
let server = undefined;
const test_factory = new TestFactory();

beforeAll(function(done) {
Expand Down
3 changes: 1 addition & 2 deletions test/unit_tests/announce/AnnounceServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@

'use strict';

let server = undefined;

describe('z.announce.AnnounceService', function() {
let server = undefined;
const test_factory = new window.TestFactory();

beforeAll(function(done) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit_tests/assets/AssetCryptoSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('AssetsCrypto', function() {

z.assets.AssetCrypto.encrypt_aes_asset(bytes.buffer)
.then(function({cipher_text, key_bytes, sha256}) {
z.assets.AssetCrypto.decrypt_aes_asset(cipher_text, key_bytes, sha256);
return z.assets.AssetCrypto.decrypt_aes_asset(cipher_text, key_bytes, sha256);
})
.then(function(buffer) {
expect(buffer).toEqual(bytes.buffer);
Expand All @@ -41,7 +41,7 @@ describe('AssetsCrypto', function() {

z.assets.AssetCrypto.encrypt_aes_asset(bytes.buffer)
.then(function({cipher_text, key_bytes}) {
z.assets.AssetCrypto.decrypt_aes_asset(cipher_text, key_bytes, null);
return z.assets.AssetCrypto.decrypt_aes_asset(cipher_text, key_bytes, null);
})
.then(done.fail)
.catch(done);
Expand All @@ -53,7 +53,7 @@ describe('AssetsCrypto', function() {

z.assets.AssetCrypto.encrypt_aes_asset(bytes.buffer)
.then(function({cipher_text, key_bytes}) {
z.assets.AssetCrypto.decrypt_aes_asset(cipher_text, key_bytes, new Uint8Array([]));
return z.assets.AssetCrypto.decrypt_aes_asset(cipher_text, key_bytes, new Uint8Array([]));
})
.then(done.fail)
.catch(done);
Expand Down
62 changes: 31 additions & 31 deletions test/unit_tests/calling/v2/CallCenterSpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe 'z.calling.v2.CallCenter', ->
build_user = (name, is_self = false) ->
user_et = new z.entity.User z.util.create_random_uuid()
user_et.name name
user_repository.save_user user_et, is_self
TestFactory.user_repository.save_user user_et, is_self
return user_et

user_ets =
Expand All @@ -108,21 +108,21 @@ describe 'z.calling.v2.CallCenter', ->
wiggum: build_user 'Chief Clarence Wiggum'

# Feed ConversationRepository with a conversation entity
conversation_et = conversation_repository.conversation_mapper.map_conversation entities.conversation
conversation_et = TestFactory.conversation_repository.conversation_mapper.map_conversation entities.conversation
conversation_et.participating_user_ids.push user_ets.marge.id
conversation_repository.conversations.push conversation_et
conversation_repository.active_conversation conversation_et
conversation_repository.update_participating_user_ets conversation_et, undefined, true
TestFactory.conversation_repository.conversations.push conversation_et
TestFactory.conversation_repository.active_conversation conversation_et
TestFactory.conversation_repository.update_participating_user_ets conversation_et, undefined, true

# Overrides
z.util.Environment.browser.supports.calling = true
v2_call_center.request_media_stream = -> Promise.resolve()
TestFactory.v2_call_center.request_media_stream = -> Promise.resolve()
done()
.catch done.fail

beforeEach ->
jasmine.Ajax.install()
v2_call_center.calls []
TestFactory.v2_call_center.calls.removeAll()

afterEach ->
jasmine.Ajax.uninstall()
Expand Down Expand Up @@ -151,12 +151,12 @@ describe 'z.calling.v2.CallCenter', ->

it 'handles call and flow creation', (done) ->
# Create call entity
conversation_et = conversation_repository.conversations()[0]
conversation_et = TestFactory.conversation_repository.conversations()[0]
conversation_id = conversation_et.id
v2_call_center.state_handler._create_call scenario_1.event_1
TestFactory.v2_call_center.state_handler._create_call scenario_1.event_1
.then (call_et) =>
expect(call_et.id).toEqual conversation_id
expect(conversation_repository.active_conversation().id).toEqual conversation_id
expect(TestFactory.conversation_repository.active_conversation().id).toEqual conversation_id

# Use the call entity to construct a flow
flow_id = 'c3cf9efb-61a0-48b2-99ec-b6b7c88ca029'
Expand Down Expand Up @@ -214,13 +214,13 @@ describe 'z.calling.v2.CallCenter', ->
"id": "2592f48d-af30-4183-a4d3-1c6ecb758b96"
}

creator_id = v2_call_center.get_creator_id call_state_event
creator_id = TestFactory.v2_call_center.get_creator_id call_state_event
expect(creator_id).toEqual '36876ec6-9481-41db-a6a8-94f92953c538'
creator_id = v2_call_center.get_creator_id post_for_flows_payload
creator_id = TestFactory.v2_call_center.get_creator_id post_for_flows_payload
expect(creator_id).toEqual post_for_flows_payload.creator

xit 'updates the call info when two remote users have a call in a group conversation with us', (done) ->
spyOn(v2_call_center, '_on_event_in_supported_browsers').and.callThrough()
spyOn(TestFactory.v2_call_center, '_on_event_in_supported_browsers').and.callThrough()

# @formatter:off
events = [
Expand All @@ -233,12 +233,12 @@ describe 'z.calling.v2.CallCenter', ->
for event in events
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, event

expect(v2_call_center._on_event_in_supported_browsers.calls.count()).toBe 2
expect(TestFactory.v2_call_center._on_event_in_supported_browsers.calls.count()).toBe 2

# Checking call entity states
expect(v2_call_center.calls().length).toBe 1
expect(TestFactory.v2_call_center.calls().length).toBe 1

v2_call_center.get_call_by_id conversation_et.id
TestFactory.v2_call_center.get_call_by_id conversation_et.id
.then (call_et) =>
expect(call_et.get_number_of_participants()).toBe 2
# Check that the first user who set his/her state to "joined" is marked as the creator of the call
Expand All @@ -264,7 +264,7 @@ describe 'z.calling.v2.CallCenter', ->
expect(mock.process_request "#{test_factory.settings.connection.rest_url.rest_url}/conversations/#{conversation_et.id}/call/state", 'PUT', {"self":{"state":"joined"}}).toBe true
#@formatter:on

v2_call_center.get_call_by_id conversation_et.id
TestFactory.v2_call_center.get_call_by_id conversation_et.id
.then (call_et) =>
expect(call_et).toBeDefined()
expect(call_et.creator().name()).toBe user_ets.homer.name()
Expand All @@ -277,7 +277,7 @@ describe 'z.calling.v2.CallCenter', ->
it 'recognizes an incoming 1-to-1 call which is ongoing on another client', (done) ->
#@formatter:off
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, {"sequence":20,"session":"54e1fd34-fc9f-4de5-85e6-8bd50e63534e","cause":"requested","self":null,"type":"call.state","conversation":"#{conversation_et.id}","participants":{"#{user_ets.marge.id}":{"state":"joined"},"#{user_ets.homer.id}":{"state":"idle"}}}
v2_call_center.get_call_by_id conversation_et.id
TestFactory.v2_call_center.get_call_by_id conversation_et.id
.then (call_et) =>
expect(call_et.get_number_of_participants()).toEqual 1
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, {"sequence":21,"session":"54e1fd34-fc9f-4de5-85e6-8bd50e63534e","cause":"requested","self":null,"type":"call.state","conversation":"#{conversation_et.id}","participants":{"#{user_ets.marge.id}":{"state":"joined"},"#{user_ets.homer.id}":{"state":"joined"}}}
Expand All @@ -296,7 +296,7 @@ describe 'z.calling.v2.CallCenter', ->
#@formatter:off
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, {"sequence":14,"session":"9ec49daf-a28f-4778-8015-2de1e0147639","cause":"requested","self":null,"type":"call.state","conversation":"#{conversation_et.id}","participants":{"#{user_ets.marge.id}":{"state":"idle","quality":null},"#{user_ets.homer.id}":{"state":"joined","quality":null}}}
#@formatter:on
v2_call_center.get_call_by_id conversation_et.id
TestFactory.v2_call_center.get_call_by_id conversation_et.id
.then (call_et) =>
expect(call_et).toBeDefined()
expect(call_et.self_user_joined()).toBeTruthy()
Expand All @@ -310,7 +310,7 @@ describe 'z.calling.v2.CallCenter', ->
it 'recognizes an incoming group call which is ongoing on another client', (done) ->
#@formatter:off
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, {"sequence":1285,"session":"ad31842f-1cc8-418c-aaa9-9847a8b2da4c","cause":"requested","self":null,"type":"call.state","conversation":"#{conversation_et.id}","participants":{"#{user_ets.marge.id}":{"state":"idle","quality":null},"#{user_ets.bart.id}":{"state":"idle","quality":null},"#{user_ets.lisa.id}":{"state":"idle","quality":null},"#{user_ets.maggie.id}":{"state":"joined","quality":null},"#{user_ets.flanders.id}":{"state":"idle","quality":null},"#{user_ets.burns.id}":{"state":"idle","quality":null},"#{user_ets.homer.id}":{"state":"idle","quality":null},"#{user_ets.wiggum.id}":{"state":"idle","quality":null},"#{user_ets.bob.id}":{"state":"idle","quality":null}}}
v2_call_center.get_call_by_id conversation_et.id
TestFactory.v2_call_center.get_call_by_id conversation_et.id
.then (call_et) =>
expect(call_et.get_number_of_participants()).toEqual 1
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, {"sequence":1286,"session":"ad31842f-1cc8-418c-aaa9-9847a8b2da4c","cause":"requested","self":null,"type":"call.state","conversation":"#{conversation_et.id}","participants":{"#{user_ets.marge.id}":{"state":"idle","quality":null},"#{user_ets.bart.id}":{"state":"idle","quality":null},"#{user_ets.lisa.id}":{"state":"idle","quality":null},"#{user_ets.maggie.id}":{"state":"joined","quality":null},"#{user_ets.flanders.id}":{"state":"idle","quality":null},"#{user_ets.burns.id}":{"state":"idle","quality":null},"#{user_ets.homer.id}":{"state":"idle","quality":null},"#{user_ets.wiggum.id}":{"state":"idle","quality":null},"#{user_ets.bob.id}":{"state":"joined","quality":null}}}
Expand All @@ -332,7 +332,7 @@ describe 'z.calling.v2.CallCenter', ->
it 'recognizes an outgoing group call which is ongoing on another client', (done) ->
#@formatter:off
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, {"sequence":1304,"session":"5b1b6e6e-d961-485d-9c57-b36965ec9254","cause":"requested","self":null,"type":"call.state","conversation":"#{conversation_et.id}","participants":{"#{user_ets.marge.id}":{"state":"idle","quality":null},"#{user_ets.bart.id}":{"state":"idle","quality":null},"#{user_ets.lisa.id}":{"state":"idle","quality":null},"#{user_ets.maggie.id}":{"state":"idle","quality":null},"#{user_ets.flanders.id}":{"state":"idle","quality":null},"#{user_ets.burns.id}":{"state":"idle","quality":null},"#{user_ets.homer.id}":{"state":"joined","quality":null},"#{user_ets.wiggum.id}":{"state":"idle","quality":null},"#{user_ets.bob.id}":{"state":"idle","quality":null}}}
v2_call_center.get_call_by_id conversation_et.id
TestFactory.v2_call_center.get_call_by_id conversation_et.id
.then (call_et) =>
expect(call_et.get_number_of_participants()).toEqual 0
amplify.publish z.event.WebApp.CALL.EVENT_FROM_BACKEND, {"sequence":1305,"session":"5b1b6e6e-d961-485d-9c57-b36965ec9254","cause":"requested","self":null,"type":"call.state","conversation":"#{conversation_et.id}","participants":{"#{user_ets.marge.id}":{"state":"idle","quality":null},"#{user_ets.bart.id}":{"state":"idle","quality":null},"#{user_ets.lisa.id}":{"state":"idle","quality":null},"#{user_ets.maggie.id}":{"state":"joined","quality":null},"#{user_ets.flanders.id}":{"state":"idle","quality":null},"#{user_ets.burns.id}":{"state":"idle","quality":null},"#{user_ets.homer.id}":{"state":"joined","quality":null},"#{user_ets.wiggum.id}":{"state":"idle","quality":null},"#{user_ets.bob.id}":{"state":"idle","quality":null}}}
Expand Down Expand Up @@ -381,7 +381,7 @@ describe 'z.calling.v2.CallCenter', ->
'session': 'b24dfebe-add9-4f2a-8953-3a1947a7b929'
}

v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
TestFactory.v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
.then (response) ->
expect(response).toEqual response_payload
done()
Expand All @@ -396,14 +396,14 @@ describe 'z.calling.v2.CallCenter', ->
'member_count': 11
'message': 'too many members for calling'
}
spyOn v2_call_center.media_stream_handler, 'release_media_stream'
spyOn TestFactory.v2_call_center.media_stream_handler, 'release_media_stream'

v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
TestFactory.v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
.then done.fail
.catch (error) ->
expect(error).toEqual jasmine.any z.calling.v2.CallError
expect(error.type).toBe z.calling.v2.CallError::TYPE.CONVERSATION_TOO_BIG
expect(v2_call_center.media_stream_handler.release_media_stream).toHaveBeenCalled()
expect(TestFactory.v2_call_center.media_stream_handler.release_media_stream).toHaveBeenCalled()
done()
server.requests[0].respond 409, 'Content-Type': 'application/json', JSON.stringify error_payload

Expand All @@ -414,14 +414,14 @@ describe 'z.calling.v2.CallCenter', ->
'max_joined': 5
'message': 'the voice channel is full'
}
spyOn v2_call_center.media_stream_handler, 'release_media_stream'
spyOn TestFactory.v2_call_center.media_stream_handler, 'release_media_stream'

v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
TestFactory.v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
.then done.fail
.catch (error) ->
expect(error).toEqual jasmine.any z.calling.v2.CallError
expect(error.type).toBe z.calling.v2.CallError::TYPE.VOICE_CHANNEL_FULL
expect(v2_call_center.media_stream_handler.release_media_stream).toHaveBeenCalled()
expect(TestFactory.v2_call_center.media_stream_handler.release_media_stream).toHaveBeenCalled()
done()
server.requests[0].respond 409, 'Content-Type': 'application/json', JSON.stringify error_payload

Expand All @@ -431,13 +431,13 @@ describe 'z.calling.v2.CallCenter', ->
'label': 'invalid-op'
'message': 'Nobody left to call'
}
spyOn v2_call_center.media_stream_handler, 'release_media_stream'
spyOn TestFactory.v2_call_center.media_stream_handler, 'release_media_stream'

v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
TestFactory.v2_call_center.state_handler._put_state conversation_et.id, {state: z.calling.enum.ParticipantState.JOINED, videod: false}
.then done.fail
.catch (error) ->
expect(error).toEqual jasmine.any z.calling.v2.CallError
expect(error.type).toBe z.calling.v2.CallError::TYPE.CONVERSATION_EMPTY
expect(v2_call_center.media_stream_handler.release_media_stream).toHaveBeenCalled()
expect(TestFactory.v2_call_center.media_stream_handler.release_media_stream).toHaveBeenCalled()
done()
server.requests[0].respond 400, 'Content-Type': 'application/json', JSON.stringify error_payload
2 changes: 1 addition & 1 deletion test/unit_tests/entity/UserSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('z.entity.User', function() {
expect(user_et.accent_color()).toBe(z.entity.User.ACCENT_COLOR.PURPLE);

user_et.accent_id(z.config.ACCENT_ID.RED);
expect(user_et.accent_color()).toBe(user_et.ACCENT_COLOR.RED);
expect(user_et.accent_color()).toBe(z.entity.User.ACCENT_COLOR.RED);

user_et.accent_id(z.config.ACCENT_ID.YELLOW);
expect(user_et.accent_color()).toBe(z.entity.User.ACCENT_COLOR.YELLOW);
Expand Down
32 changes: 16 additions & 16 deletions test/unit_tests/links/LinkPreviewProtoBuilderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@

// grunt test_init && grunt test_run:links/LinkPreviewProtoBuilder

const compare_article_with_mock = function(url, offset, preview, mock) {
expect(preview).toBeDefined();
expect(preview.preview).toBe('article');
expect(preview.url).toBe(url);
expect(preview.url_offset).toBe(offset);
expect(preview.article.title).toBe(mock.title);
expect(preview.article.permanent_url).toBe(mock.url);
expect(preview.article.summary).toEqual(mock.description || null);
expect(() => preview.toArrayBuffer()).not.toThrow();
};
describe('LinkPreviewProtoBuilder', function() {
const compare_article_with_mock = function(url, offset, preview, mock) {
expect(preview).toBeDefined();
expect(preview.preview).toBe('article');
expect(preview.url).toBe(url);
expect(preview.url_offset).toBe(offset);
expect(preview.article.title).toBe(mock.title);
expect(preview.article.permanent_url).toBe(mock.url);
expect(preview.article.summary).toEqual(mock.description || null);
expect(() => preview.toArrayBuffer()).not.toThrow();
};

beforeAll(function(done) {
z.util.protobuf.load_protos('ext/proto/generic-message-proto/messages.proto')
.then(done)
.catch(done.fail);
});
beforeAll(function(done) {
z.util.protobuf.load_protos('ext/proto/generic-message-proto/messages.proto')
.then(done)
.catch(done.fail);
});

describe('build_from_open_graph_data', function() {
it('returns undefined if no data is given', function() {
const link_preview = z.links.LinkPreviewProtoBuilder.build_from_open_graph_data();
expect(link_preview).not.toBeDefined();
Expand Down
Loading

0 comments on commit e8f672a

Please sign in to comment.