ihp icon indicating copy to clipboard operation
ihp copied to clipboard

Refactor Tests to have default values for `CreateTable { .. }` expressions

Open mpscholten opened this issue 1 year ago • 6 comments

Right now our tests have a lot of expressions like this:

                    StatementCreateTable CreateTable {
                        name = "users"
                        , columns = [
                            Column
                                { name = "id"
                                , columnType = PUUID
                                , defaultValue = Just (CallExpression "uuid_generate_v4" [])
                                , notNull = True
                                , isUnique = False
                                , generator = Nothing
                                }
                        ]
                        , primaryKeyConstraint = PrimaryKeyConstraint ["id"]
                        , constraints = []
                        , unlogged = False
                        }

In that expression constraints = [] and unlogged = False are the default values, and are basically just overhead.

Now whenever we need to add a new field to the CreateTable constructor, we have to add the new field across the full test code base. E.g. in https://github.com/digitallyinduced/ihp/commit/540106bb24a84294a3828dd4a574682b343806b5 there's a lot of boilerplate by adding unlogged = False everywhere.

As a solution we could introduce a helper function emptyCreateTable, and then use it like this:

-- Definition:
emptyCreateTable = CreateTable { name = "", columns = [], primaryKeyConstraint = [], constraints = [], unlogged = False }

-- Usage:
                    StatementCreateTable emptyCreateTable {
                        name = "users"
                        , columns = [
                            Column
                                { name = "id"
                                , columnType = PUUID
                                , defaultValue = Just (CallExpression "uuid_generate_v4" [])
                                , notNull = True
                                , isUnique = False
                                , generator = Nothing
                                }
                        ]
                        , primaryKeyConstraint = PrimaryKeyConstraint ["id"]
                        }

This way we can remove lots of boilerplate in the tests.

mpscholten avatar Feb 05 '23 13:02 mpscholten

I'm doing this one but I'm a bit rusty in working out how to make the pull request. I'll try and figure before I sleep.

tobz619 avatar Mar 25 '23 22:03 tobz619

Is this issue still open ? @tobz619 do you want a helping hand in it ?

Shobhitsingh-2503 avatar Jun 30 '23 12:06 Shobhitsingh-2503

Hi,

Sure go for it! I'm quite bogged down with work right now so if you want to help complete it then go ahead!

Thanks,

Tobi

On Fri, 30 Jun 2023, 13:44 Shobhit Singh, @.***> wrote:

Is this issue still open ? @tobz619 https://github.com/tobz619 do you want a helping hand in it ?

— Reply to this email directly, view it on GitHub https://github.com/digitallyinduced/ihp/issues/1601#issuecomment-1614600143, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWH5OJOUIRWUDW7YHM63O5TXN3C3NANCNFSM6AAAAAAURZHCIY . You are receiving this because you were mentioned.Message ID: @.***>

tobz619 avatar Jul 07 '23 17:07 tobz619

Please look into it, I have made the pull request

Shobhitsingh-2503 avatar Jul 07 '23 18:07 Shobhitsingh-2503

is this one still open? The pull request was Closed.

martinhelmer avatar Feb 01 '24 11:02 martinhelmer

This is still open 👍

mpscholten avatar Feb 01 '24 15:02 mpscholten