I hit an API which gives a list of chairs with their location. I save this data in my local database. Whenever I received updated data like add a new chair, update location of the chairs and delete a chair from the API, I must sync server data with my local database. I also assigned these chairs with different sections in the local database.
Chair server class:
- Description (unique key)
Local DB class:
- Description (Unique)
I have a Section Table in local database. It has two columns i.e. SectionID and SectionName.
Also, there is a relational table between chairs and sections. It has two columns.
I have a SectionChair Table in database has also two columns i.e. SectionID and ChairLocalDbId.
Below are different test cases:
Sync with same location of chairs =>
One :If multiple chairs are coming with same location, it shouldn’t add into local database. It should show a message to the user – show duplicate chairs with location to the user.
Two: First time, I did a sync and a chair (chairOne) is added with location ‘locOne’ in the local database. Now, I will add one or more chairs (chairTwo) with same location ‘locOne’. So, when I do Sync, it will not add chairTwo in localdatabase and also not delete chairOne from the local database. It just shows a message to the user – show duplicate machines with location to the user.
Delete a chair from the Server (API) =>
If a chair is deleted from the server, it should be deleted from the local database. Validation: if a chair is assigned to any sections, it shouldn’t be deleted. It should give an exception –“ please first unassigned this chair from the Section and sync again.
Add a new chair from the Server (API) =>
If a chair is added in the server, it should be added into local database.
Swapping Locations =>
One: 3. If we swap a two or more chairs in the API, location should be also swap in the local database. Example: Chair 234 on locOne location and Chair 345 on locTwo location in both the API and local database. After that, user swap the machines in the API like Chair 234 on locTwo location and Chair 345 on locOne location. When I do sync, the same swap should be happen in the local database and update the new location for the chair in the local database.
Two:4. Major issue: if we do swap like first point, Section should also be updated into SectionChair table. Example : Chair 234 is located in 562 and is assigned to Section 5 place X. It is switched with chair 789 located in 223 which is in Sections 8 Place Y. When synced, chair 234 should change to Section 8 Place Y and chair 789 should change to Section 5 Place X.
Please suggest me a good approach.