import unittest

from app.services.company_jobs_sync import CompanyJobsSyncService


class CompanyJobsSyncServiceTests(unittest.TestCase):
    def test_extract_boss_jobs(self):
        payload = {
            "zpData": {
                "jobList": [
                    {"encryptJobId": "job-1"},
                    {"encryptJobId": "job-2"},
                ]
            }
        }
        jobs = CompanyJobsSyncService._extract_boss_jobs(payload)
        self.assertEqual(len(jobs), 2)

    def test_extract_qcwy_jobs(self):
        payload = {
            "resultbody": {
                "job": {
                    "items": [
                        {"jobId": "1001"},
                        {"jobId": "1002"},
                    ]
                }
            }
        }
        jobs = CompanyJobsSyncService._extract_qcwy_jobs(payload)
        self.assertEqual(len(jobs), 2)

    def test_extract_zhilian_jobs(self):
        payload = {
            "data": {
                "list": [
                    {"number": "zl-1"},
                    {"number": "zl-2"},
                ]
            }
        }
        jobs = CompanyJobsSyncService._extract_zhilian_jobs(payload)
        self.assertEqual(len(jobs), 2)

    def test_extract_zhilian_jobs_from_top_level_list(self):
        payload = {
            "list": [
                {"number": "zl-top-1"},
                {"number": "zl-top-2"},
            ]
        }
        jobs = CompanyJobsSyncService._extract_zhilian_jobs(payload)
        self.assertEqual(len(jobs), 2)


if __name__ == "__main__":
    unittest.main()
