Skip to content

Commit

Permalink
chore: add tests for AC in Aggregates.unwind
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshusinghs committed Nov 25, 2024
1 parent a979614 commit 87f30f9
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,67 @@ public class Repository {
},
)
}

@ParsingTest(
fileName = "Repository.java",
value = """
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.util.List;
import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.*;
public class Repository {
private final MongoClient client;
public Repository(MongoClient client) {
this.client = client;
}
public void exampleFind() {
client.getDatabase("myDatabase").getCollection("myCollection")
.aggregate(List.of(
Aggregates.unwind("<caret>")
));
}
}
""",
)
fun `should autocomplete fields from the current namespace in an Aggregates#unwind stage`(
fixture: CodeInsightTestFixture,
) {
fixture.specifyDialect(JavaDriverDialect)

val (dataSource, readModelProvider) = fixture.setupConnection()
val namespace = Namespace("myDatabase", "myCollection")

`when`(
readModelProvider.slice(eq(dataSource), eq(GetCollectionSchema.Slice(namespace)))
).thenReturn(
GetCollectionSchema(
CollectionSchema(
namespace,
BsonObject(
mapOf(
"myField" to BsonString,
),
),
),
),
)

val elements = fixture.completeBasic()

assertTrue(
elements.containsElements {
it.lookupString == "myField"
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,68 @@ public class Repository {
},
)
}

@ParsingTest(
fileName = "Repository.java",
value = """
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Aggregates;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.types.ObjectId;
import java.util.List;
import static com.mongodb.client.model.Filters.*;
import static com.mongodb.client.model.Updates.*;
public class Repository {
private final MongoClient client;
public Repository(MongoClient client) {
this.client = client;
}
public void exampleFind() {
client.getDatabase("myDatabase").getCollection("myCollection")
.aggregate(List.of(
Aggregates.unwind(<caret>)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace in an Aggregates#unwind stage`(
fixture: CodeInsightTestFixture,
) {
fixture.specifyDialect(JavaDriverDialect)

val (dataSource, readModelProvider) = fixture.setupConnection()
val namespace = Namespace("myDatabase", "myCollection")

`when`(
readModelProvider.slice(eq(dataSource), eq(GetCollectionSchema.Slice(namespace)))
).thenReturn(
GetCollectionSchema(
CollectionSchema(
namespace,
BsonObject(
mapOf(
"myField" to BsonString,
),
),
),
),
)

fixture.type('"')
val elements = fixture.completeBasic()

assertTrue(
elements.containsElements {
it.lookupString == "myField"
},
)
}
}

0 comments on commit 87f30f9

Please sign in to comment.