Skip to content

Commit

Permalink
chore: merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz committed Nov 22, 2024
2 parents 28a69f8 + 2e8d11c commit 8f1391a
Show file tree
Hide file tree
Showing 11 changed files with 2,002 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,201 @@ 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.sort(
Sorts.ascending("<caret>")
)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace in Sorts#ascending of an Aggregates#sort 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"
},
)
}

@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.sort(
Sorts.descending("<caret>")
)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace in Sorts#descending of an Aggregates#sort 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"
},
)
}

@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.sort(
Sorts.orderBy(
Sorts.descending("<caret>")
)
)
));
}
}
""",
)
fun `should autocomplete fields from the current namespace in Sorts#orderBy of an Aggregates#sort 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"
},
)
}
}
Loading

0 comments on commit 8f1391a

Please sign in to comment.