|
13 | 13 | ProjectCosmosDBRepository, |
14 | 14 | ProjectCosmosDBModel, |
15 | 15 | create_dao, |
| 16 | + ProjectCosmosDBDao, |
16 | 17 | ) |
17 | 18 | from faker import Faker |
18 | 19 |
|
| 20 | +from time_tracker_api.time_entries.time_entries_dao import ( |
| 21 | + TimeEntriesCosmosDBDao, |
| 22 | +) |
| 23 | +from time_tracker_api.time_entries.time_entries_model import ( |
| 24 | + TimeEntryCosmosDBModel, |
| 25 | +) |
| 26 | +from utils.enums.status import Status |
| 27 | + |
19 | 28 | fake = Faker() |
20 | 29 |
|
21 | 30 |
|
@@ -138,3 +147,55 @@ def test_get_all_projects_with_customers( |
138 | 147 | assert isinstance(projects[0], ProjectCosmosDBModel) |
139 | 148 | assert projects[0].__dict__['customer_name'] == customer_data['name'] |
140 | 149 | assert len(projects) == 1 |
| 150 | + |
| 151 | + |
| 152 | +def test_get_recent_projects_get_all_method_should_have_been_called_with_specific_arguments( |
| 153 | + mocker, |
| 154 | +): |
| 155 | + projects_amount = 5 |
| 156 | + expected_conditions = {'status': Status.ACTIVE.value} |
| 157 | + expected_projects_ids = list( |
| 158 | + set([fake.uuid4() for i in range(projects_amount)]) |
| 159 | + ) |
| 160 | + user_time_entries = [] |
| 161 | + |
| 162 | + for project_id in expected_projects_ids: |
| 163 | + current_entry = TimeEntryCosmosDBModel( |
| 164 | + {'project_id': project_id, 'id': fake.uuid4()} |
| 165 | + ) |
| 166 | + user_time_entries.append(current_entry) |
| 167 | + |
| 168 | + mocker.patch.object( |
| 169 | + TimeEntriesCosmosDBDao, |
| 170 | + 'get_latest_entries', |
| 171 | + return_value=user_time_entries, |
| 172 | + ) |
| 173 | + project_cosmos_db_dao_get_all_mock = mocker.patch.object( |
| 174 | + ProjectCosmosDBDao, 'get_all' |
| 175 | + ) |
| 176 | + projects_dao = create_dao() |
| 177 | + |
| 178 | + projects_dao.get_recent_projects() |
| 179 | + |
| 180 | + project_cosmos_db_dao_get_all_mock.assert_called_once_with( |
| 181 | + conditions=expected_conditions, |
| 182 | + project_ids=expected_projects_ids, |
| 183 | + customer_status=Status.ACTIVE.value, |
| 184 | + ) |
| 185 | + |
| 186 | + |
| 187 | +def test_get_recent_projects_should_return_an_empty_array_if_the_user_has_no_entries( |
| 188 | + mocker, |
| 189 | +): |
| 190 | + user_time_entries = [] |
| 191 | + mocker.patch.object( |
| 192 | + TimeEntriesCosmosDBDao, |
| 193 | + 'get_latest_entries', |
| 194 | + return_value=user_time_entries, |
| 195 | + ) |
| 196 | + |
| 197 | + projects_dao = create_dao() |
| 198 | + |
| 199 | + recent_projects = projects_dao.get_recent_projects() |
| 200 | + |
| 201 | + assert len(recent_projects) == 0 |
0 commit comments