Skip to content

Commit

Permalink
adds 16 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianconcept committed Mar 2, 2024
1 parent 7ff5541 commit 17807ac
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/Mapless-Base/Mapless.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Mapless class >> isAbstract [
^ self == AnAbstractModelClass"

^ false
^ self == Mapless
]

{ #category : #testing }
Expand Down Expand Up @@ -244,7 +244,7 @@ Mapless class >> pluralName [
Any subclass can override its own custom name.
The default plural name is the singular name
in lower case plus an 's' so beware of irregular nouns."

self deprecated: 'Application responsibility'.

Check warning on line 247 in src/Mapless-Base/Mapless.class.st

View check run for this annotation

Codecov / codecov/patch

src/Mapless-Base/Mapless.class.st#L247

Added line #L247 was not covered by tests
^ self singularName , 's'
]

Expand All @@ -253,7 +253,7 @@ Mapless class >> singularName [
"Answers the string expected in a nicely designed API.
Any subclass can override its own custom name.
The default name is the class name in lowercase."

self deprecated: 'Application responsibility'.

Check warning on line 256 in src/Mapless-Base/Mapless.class.st

View check run for this annotation

Codecov / codecov/patch

src/Mapless-Base/Mapless.class.st#L256

Added line #L256 was not covered by tests
^ self name asLowercase
]

Expand Down Expand Up @@ -665,10 +665,11 @@ Mapless >> onBeforeUpsert [
]

{ #category : #actions }
Mapless >> sanitize: someFields [
"Removes someFields from the receiver."
Mapless >> sanitize: someProperties [
"Removes someProperties from the receiver."

someFields do: [ :key | self data removeKey: key ifAbsent: [ nil ] ]
someProperties do: [ :key |
self maplessData removeKey: key ifAbsent: [ nil ] ]
]

{ #category : #actions }
Expand Down
74 changes: 70 additions & 4 deletions src/Mapless-Mongo-Tests/MaplessMongoTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ MaplessMongoTest >> tearDown [
shutDown
]

{ #category : #tests }
MaplessMongoTest >> testAfterDestroyed [

| guy |
guy := SamplePerson new
firstName: 'john';
lastName: 'q';
yourself.
self assert: guy recentlyDestroyed isNil.
self do: [ guy save ].
self assert: guy recentlySaved.
self do: [ guy destroy ].
self assert: guy recentlyDestroyed
]

{ #category : #tests }
MaplessMongoTest >> testAfterSaved [

| guy |
guy := SamplePerson new
firstName: 'john';
lastName: 'q';
yourself.
self assert: guy recentlySaved isNil.
self do: [ guy save ].
self assert: guy recentlySaved
]

{ #category : #tests }
MaplessMongoTest >> testComposedAccess [
"Test proxies and its on-demand-load and DNU mechanism"
Expand Down Expand Up @@ -367,6 +395,18 @@ MaplessMongoTest >> testFindAllSorted [
self assert: found last firstName = 'Robert' ]
]

{ #category : #tests }
MaplessMongoTest >> testFirst [

| found |
repository readWriteDo: [ (self newSamplePersonNamed: 'Peter') save ].
repository readOnlyDo: [
self waitABit.
found := SamplePerson first.
self assert: found notNil.
self assert: found firstName equals: 'Peter' ]
]

{ #category : #tests }
MaplessMongoTest >> testIsUnsaved [
| guy |
Expand All @@ -377,6 +417,28 @@ MaplessMongoTest >> testIsUnsaved [
self do: [ guy save ]
]

{ #category : #tests }
MaplessMongoTest >> testMaplessClass [

| user guy reference |
self do: [
user := SampleUser new
userame: 'johnq';
yourself.
guy := SamplePerson new
firstName: 'john';
lastName: 'q';
yourself.
user person: guy.

guy save.
user save.
self assert: SamplePerson maplessClass equals: SamplePerson.
reference := SampleUser first person.
self assert: reference class equals: MaplessReference.
self assert: reference maplessClass equals: SamplePerson ]
]

{ #category : #tests }
MaplessMongoTest >> testMultipleComposedComposables [
| tags tagsOfTags tagsOfTagsOfTags loaded |
Expand Down Expand Up @@ -620,12 +682,16 @@ MaplessMongoTest >> testSaveSetsID [

{ #category : #tests }
MaplessMongoTest >> testSimpleSave [

| guy |
guy := SamplePerson new
firstName: 'john';
lastName: 'q';
yourself.
self do: [ guy save ]
firstName: 'john';
lastName: 'q';
yourself.
self do: [ guy save ].

self assert: guy isMapless.
self assert: guy recentlySaved
]

{ #category : #tests }
Expand Down
19 changes: 19 additions & 0 deletions src/Mapless-Mongo-Tests/MaplessVoyageMongoModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ MaplessVoyageMongoModelTest >> tearDown [
shutDown
]

{ #category : #tests }
MaplessVoyageMongoModelTest >> testConditionForClass [

| guy |
repository := MaplessMongoRepository
for: 'Mapless-Test'
with: MaplessStandaloneMongoPool local.
repository resolver: (MaplessVoyageWithMaplessSuffixResolver new
suffix: 'Interoperating';
yourself).
guy := SamplePersonInteroperating new.

repository resolver.
self
assert: (repository resolver conditionForClass: guy class)
equals: { ('#instanceOf' -> 'SamplePerson') } asDictionary.
self assert: repository resolver suffix equals: 'Interoperating'
]

{ #category : #tests }
MaplessVoyageMongoModelTest >> testReifyWithReferenceFromVoyageMetadata [

Expand Down
62 changes: 62 additions & 0 deletions src/Mapless-Tests/MaplessResourcesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ MaplessResourcesTest >> test30And70Chance [
self assert: j > 6800
]

{ #category : #tests }
MaplessResourcesTest >> testAddNodes [

| wr n1 n2 |
wr := MaplessWeightedRandomPolicy new.
n1 := MaplessWeightedNode new
weight: 30;
value: 'url1';
yourself.
n2 := MaplessWeightedNode new
weight: 70;
value: 'url2';
yourself.
wr nodes: {
n1.
n2 }.

self assert: wr nodes first equals: n1.
self assert: wr nodes second equals: n2
]

{ #category : #tests }
MaplessResourcesTest >> testChangeWeightedNodeWeight [

Expand Down Expand Up @@ -124,3 +145,44 @@ MaplessResourcesTest >> testPrintsWeightedNodeInAUsefulWay [

self assert: n1 asString equals: 'a MaplessWeightedNode(0.5@url1)'
]

{ #category : #tests }
MaplessResourcesTest >> testRandom [

| wr n1 n2 thisOne |
wr := MaplessWeightedRandomPolicy seed: 1000.
n1 := MaplessWeightedNode new
weight: 30;
value: 'url1';
yourself.
n2 := MaplessWeightedNode new
weight: 70;
value: 'url2';
yourself.
wr nodes: {
n1.
n2 }.
wr recalculateWeight.
thisOne := wr next.
self assert: (thisOne = n1 or: [ thisOne = n2 ])
]

{ #category : #tests }
MaplessResourcesTest >> testWeights [

| wr n1 n2 |
wr := MaplessWeightedRandomPolicy seed: 1000.
n1 := MaplessWeightedNode new
weight: 30;
value: 'url1';
yourself.
n2 := MaplessWeightedNode new
weight: 70;
value: 'url2';
yourself.
wr nodes: {
n1.
n2 }.
wr recalculateWeight.
self assert: wr totalWeight equals: 100
]
44 changes: 43 additions & 1 deletion src/Mapless-Tests/MaplessTestCase.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Class {
#category : #'Mapless-Tests-Tests'
}

{ #category : #tests }
MaplessTestCase >> testAbstract [

self assert: Mapless isAbstract.
self deny: SamplePerson isAbstract
]

{ #category : #tests }
MaplessTestCase >> testDeprecated [

self deny: SamplePerson isDeprecated
]

{ #category : #tests }
MaplessTestCase >> testGetterReturn [
| guy |
Expand All @@ -14,12 +27,21 @@ MaplessTestCase >> testGetterReturn [
self assert: guy firstName equals: 'John'
]

{ #category : #tests }
MaplessTestCase >> testMaplessClass [

self assert: Mapless maplessClass equals: Mapless.
self assert: SamplePerson maplessClass equals: SamplePerson
]

{ #category : #tests }
MaplessTestCase >> testMaplessErrorDefaultAction [

self
should: [ MaplessError signal: 'mmmmmmmmm...' ]
raise: MaplessError
raise: MaplessError.

self should: [ MaplessError new defaultAction ] raise: UnhandledError
]

{ #category : #tests }
Expand Down Expand Up @@ -47,6 +69,26 @@ MaplessTestCase >> testPoolBasics [
self deny: pool hasHealthChecker
]

{ #category : #tests }
MaplessTestCase >> testSanitizeProperties [

| guy |
guy := SamplePerson new.
self assert: guy firstName isNil.
guy
firstName: 'John';
lastName: 'Carpenter';
phone: '1234'.

self assert: guy firstName notNil.
self assert: guy firstName equals: 'John'.
self deny: guy phone isNil.
guy sanitize: { #phone }.
self deny: guy phone notNil.
self assert: guy firstName equals: 'John'.

]

{ #category : #tests }
MaplessTestCase >> testSetterReturn [
| guy set |
Expand Down
16 changes: 16 additions & 0 deletions src/Mapless-Tests/SamplePerson.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@ Class {
#superclass : #Mapless,
#category : #'Mapless-Tests-Samples'
}

{ #category : #hooks }
SamplePerson >> onAfterDestroy [

super onAfterDestroy.

self recentlyDestroyed: true
]

{ #category : #hooks }
SamplePerson >> onAfterSave [

super onAfterSave.

self recentlySaved: true
]

0 comments on commit 17807ac

Please sign in to comment.