Commit graph

34 commits

Author SHA1 Message Date
Sonja Happ
678b39a3c2 remove tage unique from Model.ID since it destroys many2many relationship 2019-09-03 16:37:26 +02:00
Sonja Happ
0e96f643e5 remove not null tag from scenario users field and add semicolons 2019-09-03 15:24:13 +02:00
Sonja Happ
95dc4998cf use spaces instead of commas to separate tags of model definitions 2019-09-03 12:46:19 +02:00
smavros
f4a15e914e Merge branch 'master' into test-user-endpoints 2019-08-30 15:47:54 +02:00
smavros
59a37bf601 Removes Credentials type from common/models.go:
Every test will fail except from the user's package since it is the
    only one using the new Request type.
2019-08-13 19:21:39 +02:00
smavros
28d81e52c2 Derpecates UsersSerializer() from user endpoints 2019-08-13 16:17:37 +02:00
smavros
0fb9bc9157 Fix of User.ID serialization:
As @skolen mentioned out, the `ID` field of the embedded struct
    `Model` in the model `User` must be serialized so it can be included
    in the responses. In the previous commit we completely ignored the
    field with the tag `json:"-"` so we can compare the serialized
    request (where ID was 0) with the response of the API.

    To limit the omission of the `User.ID` field only for the case that
    its value is 0 we modify the tag to `json:",omitempty"`.
2019-08-13 11:15:36 +02:00
smavros
76658c3ed4 Bug fix (read that commit message!):
The problem started with an internal error in the database (HTTP
    code 500, pq: duplicate key value) while trying to POST at /api/user
    with body {"user":{newUserObject}} to the backend, that already had
    three users User0 (Admin), UserA and UserB. Every test was
    succeeding.

    Eventually, the source of the problem was the initialization of the
    field `ID` (primary key) of the embedded struct `Model` in model
    `User`. When the `User` global variables User0, UserA and UserB
    were created in `common/testdata.go` the `Model.ID` field was set
    manually to the values 1, 2 and 3 respectively. This ofc was
    unnecessary but those variables were used for comparison with the
    relevant responses.

    When gorm (or postgres, not entirely sure) have a new variable of a
    model type, it will check if its primary key is zero (which means is
    uninitialized) and will set it to the last used value +1. That means
    that the new user that we were trying to insert in the DB got the
    primary key value 1. This value was already in use by the User0 so
    the DB refused to add the new user since there was a duplicate
    primary key value. That's why we were getting an postgre's error and
    HTTP 500.

    Hence to fix the bug this commit:

    - Removes `User.ID` initialization from `common/testdata.go`

    - Omits the `User.ID` from the json marshaler by setting the struct
    json tag to `json:"-"`. This is done because the request body is
    compared to the response *after* is serialized by a call to
    json.Marshal(). Since the `User.ID` is always uninitialized (value
    0) the jsondiff.Compare() will always return a "NoMatch".

    - Includes check for return of "SupersetMatch" in
    NewTestEndpoint()'s jsondiff.Compare() call. Since the `User.ID` is
    not serialized the json representation of the request will not
    include an "id" key. On the contrary, the response *has* an "id" key
    so it will always going to be a superset json object of the
    serialized request.

    - Modifies the validator's data struct to match the form of the
    request ({"modelKey":{requestBody}}) by adding an intermediate
    struct with the proper tag `json:"user"`.
2019-08-13 01:45:24 +02:00
smavros
8f5c47dde9 Tags ID of Model as unique field 2019-08-10 22:41:43 +02:00
smavros
61ccdb00c6 Changes to model's tags:
For multiple tag strings use __single space__ as separator according
    to the ```reflect``` package. Commas will __NOT__ work. That way the
    tags can be ordered arbitrarily.
2019-08-04 18:15:01 +02:00
Sonja Happ
ee708e1b7b Use capital letter for CommonModelFields type 2019-07-31 12:56:40 +02:00
Sonja Happ
05a70f80f6 add json tags to all models 2019-07-31 09:37:12 +02:00
smavros
cf69e59a5f Modifies testdata setup:
- Decorates User model with json tags for marshaling.
    - Introduces Model type same as gorm.Model with additional json tags
    for marshaling.
    - Modifies ResponseMsgUsers type.
    - Modifies the testdata for the users by including initializer for
    the Mode.ID field.
    - The scenario test fails for those changes
2019-07-30 20:31:59 +02:00
Sonja Happ
c57b083eed add gorm.Model in all DB models 2019-07-25 12:41:31 +02:00
Sonja Happ
a06d90d085 revise dashboard testing 2019-07-25 11:38:28 +02:00
Sonja Happ
d79fb53cb2 - create all test data in one file
- revise testing functions (WORK IN PROGRESS)
2019-07-25 11:22:39 +02:00
Sonja Happ
eb277fc92e use jsondiff in endpoint testing 2019-07-24 13:17:47 +02:00
Sonja Happ
65cc819874 remove unique requirement from UUID 2019-07-23 17:20:25 +02:00
Sonja Happ
54b4a5d7b1 change datatypes of simulator properties and raw properties to json, small ajustments for frontend compatibility 2019-07-23 14:53:52 +02:00
Sonja Happ
b378e8b7c1 renaming simulation to scenario 2019-07-18 14:35:20 +02:00
Sonja Happ
c33438b395 renaming visualization to dashboard 2019-07-18 13:11:05 +02:00
Sonja Happ
ccdbea918f fix in File model (remove a comment that irritated swaggo) 2019-07-04 11:44:18 +02:00
Sonja Happ
fc91ebc64c working on file endpoints; testing to be completed, other tests to be checked 2019-07-03 16:53:04 +02:00
Sonja Happ
ce4d6525eb - fix in DB testing
- add simulator testing
2019-06-25 17:11:03 +02:00
Sonja Happ
2973718d86 change data model to use Simulator has many SimulationModels 2019-06-18 14:07:08 +02:00
Sonja Happ
86e380c85e - implement simulator endpoints
- add field for simulation models to simulator models and adapt methods for adding/updating a model
- minor renaming of test functions
2019-06-18 13:55:10 +02:00
Sonja Happ
7c9318de8f add testing for widget endpoints 2019-06-17 14:15:39 +02:00
Sonja Happ
687e3863e4 add testing for visualization endpoints 2019-06-17 13:43:30 +02:00
Sonja Happ
5ca6281a22 - add testing for simulationmodel endpoints
- add Signal serializer
- Use Signals DB table again
- remove / in some endpoint definitions
2019-06-06 16:36:12 +02:00
Sonja Happ
babe1cb308 refactoring Model to SimulationModel 2019-06-05 13:12:23 +02:00
Sonja Happ
4806583b1f Merge branch 'authentication'
# Conflicts:
#	common/models.go
#	common/utilities.go
#	routes/user/userEndpoints.go
2019-06-05 10:42:49 +02:00
Sonja Happ
d3cdf0008b - rename Modes to Permissions
- rename actions.go to roles.go
- put all role related functions in file roles.go
2019-06-05 09:38:17 +02:00
Sonja Happ
084d3ec8d8 fix many to many relationship between users and simulations 2019-06-03 14:30:15 +02:00
Sonja Happ
144c97ce49 Refactoring code base to new structure, removing circular dependencies, creating response types 2019-05-23 16:50:05 +02:00
Renamed from common/datastructs.go (Browse further)